From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by sourceware.org (Postfix) with ESMTPS id D8B7E3858D28 for ; Thu, 10 Feb 2022 12:36:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8B7E3858D28 Received: by mail-oo1-xc2d.google.com with SMTP id f11-20020a4abb0b000000b002e9abf6bcbcso6210457oop.0 for ; Thu, 10 Feb 2022 04:36:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=D4c/d3dd/XCSpWgVrBQZGljZM4sRtM4iVG2fccj4NXI=; b=zrLMYM3vtwc0zI8MXoBAF0OJniqCmL1n89f5uEgG+uAj1Hc0b2unfYXudvWVJ5M3YT 6ss6A2Vg2yp/uRHiwfvjA3axLXij7/umnJHPfHPigrdOf+YAWbkfJBHTw50U80fx1tgZ z2uZahSvTtZ43amkLknxFMxulmCbelP7n1Pf8w+MxR7YpbVm1u/NwHZ9d33UgrGPZ69/ PTMVThQBjPmIUZ67/E5hBYjIwwgGlRA1BcHdJKxfIfnPbznztob9LTy0PRRQ0z5KmbT2 pdPej2tOTQJuG867NqFLpS5zfGEqTJAgHeNHgZqKdoOsqrCdgmEaxQrf06xTHSnmnc49 fwtQ== X-Gm-Message-State: AOAM530HJ2BrzMs6MozVSfWQAJ+LA0a0pliZVQjnd3ru59GvOaBjndRE kKFu6nOtc/UkIVPgAOnjk2sKwb4ZP23wog== X-Google-Smtp-Source: ABdhPJxD2rIqmyAipcL1EZPO2v9I6lnPO1xf5TlUgwJCfrfpI3rMRVfPEH0hoQCSuGJDRU0iyLM8WQ== X-Received: by 2002:a05:6870:e1c4:: with SMTP id g4mr681467oab.199.1644496608155; Thu, 10 Feb 2022 04:36:48 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:733:a925:765e:3799:3d34? ([2804:431:c7ca:733:a925:765e:3799:3d34]) by smtp.gmail.com with ESMTPSA id y4sm7824763otj.22.2022.02.10.04.36.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Feb 2022 04:36:47 -0800 (PST) Message-ID: <40ac4645-020c-d3cd-0141-564a136e138a@linaro.org> Date: Thu, 10 Feb 2022 09:36:46 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] realpath: Do not copy result on failure (BZ #28815) Content-Language: en-US To: Siddhesh Poyarekar , libc-alpha@sourceware.org References: <20220124165409.1112537-1-siddhesh@sourceware.org> From: Adhemerval Zanella In-Reply-To: <20220124165409.1112537-1-siddhesh@sourceware.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-List-Received-Date: Thu, 10 Feb 2022 12:36:50 -0000 On 24/01/2022 13:54, Siddhesh Poyarekar via Libc-alpha wrote: > On failure, the contents of the resolved buffer passed in by the caller > to realpath are undefined. Do not copy any partial resolution to the > buffer and also do not test resolved contents in test-canon.c. > > Resolves: BZ #28815 > > Signed-off-by: Siddhesh Poyarekar LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > stdlib/canonicalize.c | 4 ++-- > stdlib/test-canon.c | 4 +++- > 2 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c > index 6caed9e70e..6237a41d42 100644 > --- a/stdlib/canonicalize.c > +++ b/stdlib/canonicalize.c > @@ -400,11 +400,11 @@ realpath_stk (const char *name, char *resolved, > > error: > *dest++ = '\0'; > - if (resolved != NULL) > + if (!failed && resolved != NULL) > { > if (dest - rname <= get_path_max ()) > rname = strcpy (resolved, rname); > - else if (!failed) > + else > { > failed = true; > __set_errno (ENAMETOOLONG); > diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c > index 185ccf4f48..2ad1218749 100644 > --- a/stdlib/test-canon.c > +++ b/stdlib/test-canon.c > @@ -174,7 +174,9 @@ do_test (int argc, char ** argv) > continue; > } > > - if (!check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved)) > + /* Only on success verify that buf contains the result too. */ > + if (result != NULL > + && !check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved)) > { > printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n", > argv[0], i, tests[i].out ? tests[i].out : tests[i].resolved,