From patchwork Wed Mar 30 04:35:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1610911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=VOkHQTBA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KStsT65Tdz9sFk for ; Wed, 30 Mar 2022 15:35:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 613BE3858405 for ; Wed, 30 Mar 2022 04:35:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 613BE3858405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1648614938; bh=+G/D5HQ3HurVe6scGki5ARTAOEetWHiwQhZAcC/qgDs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VOkHQTBAb+OkjGyGZzbmh9+0lSAvYZtA/2sunmrJbNkQw2lFpiVYVGZTA4IQDWiIn PVBH82L9vhLAPp7fmrEJ8vpW2IJTR2MvPFZQej9/hwBgMYM3xdogZHUu/ZTqGqNgo7 m41TP5L8//JwsT9Aa5buixnq6xk4gQylvOwjauek= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hamster.birch.relay.mailchannels.net (hamster.birch.relay.mailchannels.net [23.83.209.80]) by sourceware.org (Postfix) with ESMTPS id 286093858C50 for ; Wed, 30 Mar 2022 04:35:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 286093858C50 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id B8A426C0F5D; Wed, 30 Mar 2022 04:35:17 +0000 (UTC) Received: from pdx1-sub0-mail-a304.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 228E66C0F1E; Wed, 30 Mar 2022 04:35:17 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1648614917; a=rsa-sha256; cv=none; b=EeUmQ+4TL6od4DkjeHyled4EyrQwvLaoSndfDEGVR0auO+7BeSAtk9CJcgLuc1Jb1wyPrg gWtgNgsHByZQqMB/H5+GDjQtcggF3akg+2G4YuRCLE/+36H5Mty1ZI46evLJW0Z2fIwbbM 1yfXUYjGNUpyFWcob2ISywagYzPjpoBIx9e3iyqNbrqOQHpQsQYDeRW3EQslEWfXUHQQeA aqe3M4ZicmXtDFAHqI+4gWZ62BzO9miSRoyhyGTgMijaTgv5Ll2DPYJNloJCdKYUTk5ff+ FEPBINPoMfJx0M7L0UkPDF1Mn86irmWOoQqsWoKl6KXhz9HIZtzTlH7JRe6tCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1648614917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+G/D5HQ3HurVe6scGki5ARTAOEetWHiwQhZAcC/qgDs=; b=s/p/FXbPT+k4TK0EKAAYMfd62RRmsFvRq52vgDAkrrhKESulWPrJGLOdFWdZ/CzydHijfr sIhZChzSifDrWQehwYTZT9jqZcttTfvvi2pykJnsdxdOscCcTNW4nisLMAU/4Z5pR29QX3 ZnypRLeXmL482yyPBwn1BrtHoC8EpJdXYVcaBurxFhYTIB5NZAX4IhyXB9YKha60YtHVqT qO8cHG1vWK46U0UVNQs+T3QYiqlsh/oJYv2SmkI8Qh1PM9ZnHyLdf6PXDA32Gdql4UfLfY nAwUeeynbvgttmfh7AbfUJoHyRHjm+CMOPHNZ3u27l4zYm871Fjd8g00R/1PyQ== ARC-Authentication-Results: i=1; rspamd-5b56854b7c-f998p; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a304.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.38.157 (trex/6.5.3); Wed, 30 Mar 2022 04:35:17 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Troubled-Sponge: 28ae049b3b4f09f3_1648614917582_63666978 X-MC-Loop-Signature: 1648614917582:1848590567 X-MC-Ingress-Time: 1648614917582 Received: from rhbox.redhat.com (unknown [1.186.121.206]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a304.dreamhost.com (Postfix) with ESMTPSA id 4KStrz1J5Hz18q; Tue, 29 Mar 2022 21:35:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1.1] realpath: Bring back GNU extension on ENOENT and EACCES [BZ #28996] Date: Wed, 30 Mar 2022 10:05:02 +0530 Message-Id: <20220330043502.74482-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3494.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: Iker Pedrosa Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The GNU extension for realpath states that if the path resolution fails with ENOENT or EACCES and the resolved buffer is non-NULL, it will contain part of the path that failed resolution. commit 949ad78a189194048df8a253bb31d1d11d919044 broke this when it omitted the copy on failure. Bring it back partially to continue supporting this GNU extension. Resolves: BZ #28996 Signed-off-by: Siddhesh Poyarekar --- stdlib/canonicalize.c | 9 ++++++--- stdlib/test-canon.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 6237a41d42..e6566bd7d9 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -400,11 +400,14 @@ realpath_stk (const char *name, char *resolved, error: *dest++ = '\0'; - if (!failed && resolved != NULL) + if (resolved != NULL) { - if (dest - rname <= get_path_max ()) + /* Copy the full result on success or partial result if failure was due + to the path not existing or not being accessible. */ + if ((!failed || errno == ENOENT || errno == EACCES) + && dest - rname <= get_path_max ()) rname = strcpy (resolved, rname); - else + else if (!failed) { failed = true; __set_errno (ENAMETOOLONG); diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c index 2ad1218749..a9c83be17c 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -174,8 +174,8 @@ do_test (int argc, char ** argv) continue; } - /* Only on success verify that buf contains the result too. */ - if (result != NULL + /* Verify buf contents if the call succeeded or failed with ENOENT. */ + if ((result != NULL || errno == ENOENT) && !check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved)) { printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n",