From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10329 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Daniel_Cegie=C5=82ka?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: dirname() / basename() - musl vs FreeBSD and OpenBSD Date: Sun, 24 Jul 2016 21:49:15 +0200 Message-ID: References: <20160724192107.GO15995@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1469389801 24926 80.91.229.3 (24 Jul 2016 19:50:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Jul 2016 19:50:01 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-10342-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jul 24 21:49:50 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1bRPPJ-0007Q8-MB for gllmg-musl@m.gmane.org; Sun, 24 Jul 2016 21:49:49 +0200 Original-Received: (qmail 30147 invoked by uid 550); 24 Jul 2016 19:49:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30126 invoked from network); 24 Jul 2016 19:49:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=BfYLvrubRuj5hks4/fD1kqtadepEZICUdH2g00dC1qk=; b=NhP8RacUSqizN3fyIlPOHB97/WTnkomr+IoMtmNfZiJyFkYNFUPQeJpmdI17Hrrati NXHFE2GyhnD+P2JcAiSStqXq+mm+jSJftxZ73XdW6u3EPUE2MidONFuUnldedd2SUTXI eNLk2zT3cyr6/7BMgOkmnbReuXOCQhjsxXKtSbv/O+l3MaIENTndt/RhM2FgKDH6HmBp J7245sH8k/fNMcUQp+3fkmE49Ko15thfxVVLUEwIFcdPE/Qd+VgoexDFju7KQO8KtNHz jBXBCYzFlbKY00DMiNa4BEphwtzUSiaCEv81KRpQhbPJ0cWjqhpYbIn9GwAVcwJVv3Ip wQDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=BfYLvrubRuj5hks4/fD1kqtadepEZICUdH2g00dC1qk=; b=LF4b5xjfTkYelFOGVOz1l15JUxApXUWyw6PGSQttKtMBnEXe4cwz7yH9ipOVa3NWY0 zFRXvH6UtGyMJuyYoRsURNocCPAtOkU1JrjVKEa0QFHgyCHPh6wwVCCXv+bbUmJAGB8A HgEbTL8Fj3BJz7cibk05u/Ccv3yNAG4GkSvmJxzYJC/0zlN19tuHmiSatYY/NDk6n4sj EOIJE8VNDUL+uOCfVawj6FsZXj+C+VLCJks72Pp9VCr4Tcz+kx2bNQ25UEXWi4pElo+A FBqlpUY+Ssfzh0Hohlh9TMqIbYdAO+x6sYXNqWNQyVxotszJsOe6M4FAfQOPCfi2urBc Puag== X-Gm-Message-State: AEkoouvgSBa1fvhbVi9O+OxCBUGnLkg/cc64/iO8O3bWC5US3Rlp5J1Axi/jsMl2RygJx4LsPCDFjQeraBcuOA== X-Received: by 10.31.185.9 with SMTP id j9mr6905947vkf.144.1469389775281; Sun, 24 Jul 2016 12:49:35 -0700 (PDT) In-Reply-To: <20160724192107.GO15995@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:10329 Archived-At: 2016-07-24 21:21 GMT+02:00 Rich Felker : > On Sun, Jul 24, 2016 at 09:12:49PM +0200, Daniel Cegie=C5=82ka 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/dirnam= e.c?rev=3D1.15 http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/gen/basena= me.c?rev=3D1.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