From nobody@FreeBSD.org Mon Nov 17 02:05:00 2008 Return-Path: Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C420106567A for ; Mon, 17 Nov 2008 02:05:00 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id EF65D8FC1C for ; Mon, 17 Nov 2008 02:04:59 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mAH24xX0015329 for ; Mon, 17 Nov 2008 02:04:59 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id mAH24xkw015323; Mon, 17 Nov 2008 02:04:59 GMT (envelope-from nobody) Message-Id: <200811170204.mAH24xkw015323@www.freebsd.org> Date: Mon, 17 Nov 2008 02:04:59 GMT From: James Vega To: freebsd-gnats-submit@FreeBSD.org Subject: realpath(3) does not follow SUS specification for a NULL/empty path X-Send-Pr-Version: www-3.1 X-GNATS-Notify: >Number: 128933 >Category: kern >Synopsis: [libc] realpath(3) does not follow SUS specification for ENOENT / ENOTDIR conditions >Confidential: no >Severity: serious >Priority: medium >Responsible: kib >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Nov 17 02:10:02 UTC 2008 >Closed-Date: >Last-Modified: Sun Nov 13 14:25:05 UTC 2011 >Originator: James Vega >Release: >Organization: >Environment: >Description: According to the Single Unix Specification[0], 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[0] == '/' [0] - http://www.opengroup.org/onlinepubs/009695399/functions/realpath.html >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: From: Andrey Chernov To: James Vega Cc: freebsd-gnats-submit@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[0], 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[0] == '/' > > [0] - 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 with ENOTDIR. See following examples with realpath(1): # realpath /non_existent /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) -- http://ache.pp.ru/ From: "Arjan van Leeuwen" To: bug-followup@freebsd.org, vega.james@gmail.com Cc: Subject: Re: kern/128933: [libc] realpath(3) does not follow SUS specification for a NULL/empty path Date: Wed, 27 Oct 2010 16:13:33 +0200 We ran into this recently. This is a real problem in portable code, since it's not possible to assume that realpath() will notify the caller if a file doesn't exist, even though it should according to the specification. Arjan -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ Responsible-Changed-From-To: freebsd-bugs->kib Responsible-Changed-By: arundel Responsible-Changed-When: Wed Oct 27 17:51:58 UTC 2010 Responsible-Changed-Why: Please note that the NULL issue has already been fixed by r206893 and PR 121897 was closed. The issue Andrey Chernov described in his followup to this PR however remains to be fixed. Kib, could you take a look at this? http://www.freebsd.org/cgi/query-pr.cgi?pr=128933 >Unformatted: