kern/128933: realpath(3) does not follow SUS specification for
a NULL/empty path
ache at nagual.pp.ru
Tue Nov 18 01:20:03 PST 2008
The following reply was made to PR kern/128933; it has been noted by GNATS.
From: Andrey Chernov <ache at nagual.pp.ru>
To: James Vega <vega.james at gmail.com>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: kern/128933: realpath(3) does not follow SUS specification for
a NULL/empty path
Date: Tue, 18 Nov 2008 12:06:12 +0300
On Mon, Nov 17, 2008 at 02:04:59AM +0000, James Vega wrote:
> According to the Single Unix Specification, the realpath stdlib function should return NULL (to indicate an error) when the first argument to realpath is either NULL or an empty string and set errno to EINVAL/ENOENT respectively.
> For the empty string case, FreeBSD is currently populating resolved with the current working directory and returning the pointer to that.
> For the NULL case, I see no check whether path is NULL or not. Instead, the first use of it is dereferencing the pointer
> if (path == '/'
>  - http://www.opengroup.org/onlinepubs/009695399/functions/realpath.html
The situation is even worse. realpath(3) breaks those SUS rules
("shall fail if") too:
[ENOENT] A component of file_name does not name an existing file
[ENOTDIR] A component of the path prefix is not a directory
i.e. realpath(3) does not detect fictional file name (last component)
with ENOENT and does not detect intermediate non-directories components
See following examples with realpath(1):
# realpath /non_existent
(should be "No such file or directory")
# realpath /bin/non_existent/cp
realpath: /bin/non_existent/cp: No such file or directory
(should be: "Not a directory", as early as non_existent checked)
More information about the freebsd-bugs