From: "Daniel Cegiełka" <daniel.cegielka@gmail.com>
To: musl@lists.openwall.com
Subject: Re: dirname() / basename() - musl vs FreeBSD and OpenBSD
Date: Sun, 24 Jul 2016 21:49:15 +0200 [thread overview]
Message-ID: <CAPLrYERpHej4dVSLXG0kE6yxKaOTkp8D=gk2KWekK-LXFqrFPA@mail.gmail.com> (raw)
In-Reply-To: <20160724192107.GO15995@brightrain.aerifal.cx>
2016-07-24 21:21 GMT+02:00 Rich Felker <dalias@libc.org>:
> On Sun, Jul 24, 2016 at 09:12:49PM +0200, Daniel Cegiełka wrote:
>> Hi,
>>
>> I came across a very strange problem when I ports code from OpenBSD to
>> musl-libc, and it seems, that a lot of problems can be caused by
>> dirname().
>>
>> http://pubs.opengroup.org/onlinepubs/009695399/functions/dirname.html
>>
>> "The dirname() function >>> may <<< modify the string pointed to by
>> path, and may return a pointer to static storage that may then be
>> overwritten by subsequent calls to dirname()."
>
> There is actually no other option for implementing this function. The
> contract does not require that the argument string be a valid pathname
> or have a bounded length like PATH_MAX; it operates on general
> strings. And "No errors are defined", so failure is not an option. The
> only way to implement this function is for it to modify its argument.
Thank you for your answer. dirname() and basename() in OpenBSD compare
length against PATH_MAX:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/gen/dirname.c?rev=1.15
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/gen/basename.c?rev=1.15
So if someone uses the code from OpenBSD/FreeBSD needs to be careful
not to use the argument after dirname() or basename().
Best regards,
Daniel
>
> Rich
prev parent reply other threads:[~2016-07-24 19:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-24 19:12 Daniel Cegiełka
2016-07-24 19:21 ` Rich Felker
2016-07-24 19:49 ` Daniel Cegiełka [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPLrYERpHej4dVSLXG0kE6yxKaOTkp8D=gk2KWekK-LXFqrFPA@mail.gmail.com' \
--to=daniel.cegielka@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).