Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Sun, 24 Jul 2016 21:49:15 +0200
From: Daniel Cegiełka <>
Subject: Re: dirname() / basename() - musl vs FreeBSD and OpenBSD

2016-07-24 21:21 GMT+02:00 Rich Felker <>:
> 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().
>> "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:

So if someone uses the code from OpenBSD/FreeBSD needs to be careful
not to use the argument after dirname() or basename().

Best regards,

> Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.