From: Stefan Sperling Subject: Re: Got relies on non-POSIX basename(3), dirname(3) To: Christian Weisgerber Cc: gameoftrees@openbsd.org Date: Fri, 18 Sep 2020 18:39:03 +0200 On Fri, Sep 18, 2020 at 04:42:52PM +0200, Christian Weisgerber wrote: > As I mentioned on tech@, OpenBSD declares > > char *basename(const char *); > char *dirname(const char *); > > in contradiction to POSIX, which has plain char* arguments and > explicitly says that these functions may modify the string. In > fact, on FreeBSD they do. > > Unfortunately, Got relies on the string not being modified. I don't > know in how many places this breaks, nothing shows up in the > regression tests, but I stumbled over this case: > > freebsd$ got co got.git > got: realpath: /home/naddy/got: No such file or directory This is a direct consequence of not caring about portability early on. I pretty much ignored most of the portability warnings in OpenBSD man pages. Could you add basename/dirname overrides to the freebsd version which copy the string internally before use? Otherwise I don't think we could do much else but go through the basename and dirname calls one-by-one to determine whether they rely on the string to remain unmodified. Where a modifiable string is required, an easy fix would be to run strdup() first, I guess?