From owner-freebsd-bugs@FreeBSD.ORG Tue Nov 18 09:20:03 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 895FA1065673 for ; Tue, 18 Nov 2008 09:20:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 78F7A8FC16 for ; Tue, 18 Nov 2008 09:20:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id mAI9K3GP016127 for ; Tue, 18 Nov 2008 09:20:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id mAI9K3Ms016126; Tue, 18 Nov 2008 09:20:03 GMT (envelope-from gnats) Date: Tue, 18 Nov 2008 09:20:03 GMT Message-Id: <200811180920.mAI9K3Ms016126@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Andrey Chernov Cc: Subject: Re: kern/128933: realpath(3) does not follow SUS specification for a NULL/empty path X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Andrey Chernov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Nov 2008 09:20:03 -0000 The following reply was made to PR kern/128933; it has been noted by GNATS. 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/