From patchwork Wed Oct 14 20:37:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 40723 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49395394343A; Wed, 14 Oct 2020 20:37:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49395394343A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602707838; bh=mJwqbwBeenyYHgpO0OmWoY7hgytKibVioCrp2CHNXIM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aiymjPPoZJ0y0cECfyKJRIXMStmd+2DIcnBu+8S7dcvjvEnHBfGcehfmLsUIriRaa NNTGYBGecrtvEpTR7V7D4HNyNguuuU+hJrgHVGvBC3n5gGcF7JLk1D217epMzID/Id BUtY+JyNOrHodrJ2TREkUgi+PJfvoF2bEFelJouQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id B8B9A385780E for ; Wed, 14 Oct 2020 20:37:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B8B9A385780E Received: by mail-qk1-x742.google.com with SMTP id a23so593968qkg.13 for ; Wed, 14 Oct 2020 13:37:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mJwqbwBeenyYHgpO0OmWoY7hgytKibVioCrp2CHNXIM=; b=thBPPpO3Uz+hs8aiq3W37xRTZpshKQCiCh9K/+47cxhhM0D9RmELkWl40/zItKm+9v U40bLFqjnxa9DCsD4VtTvYxptURC2PNS5OFzNti6H8ALdnLG4RhPrTq7W+YyO4M7z3d/ pB7wFYZP83bdan00sQkMHKf5OxooohGOHJ8udJnesfSvhBuLfrwBCnu4EkjFKO+Gbzia maOQDWdJcrO1xzmVbKGsmVsy7oZXyrkrrS6Z7Ii+bGKFiyV0rJiHEOH8ttycpMISGmYu gU6iBH9gju0m0LbOZXff6K1znpVpg6I/ZcBDhR6vsbPS2NeMB3LFmf05whNZqvP2zILL 9mlA== X-Gm-Message-State: AOAM532tVvsn89rN+vuFy1LQVVHraeeYkyzBrXFDgudj7BnF8WoUb3jS 5gx0d0ni0k+G8Ki+QCrhb+DPBuP18ciBfQ== X-Google-Smtp-Source: ABdhPJxZ9ufFPPYGVLFbh3s1nLWxc0ZyBFticcA2E0lyM/orYlsWVS46QTurHI5kXpYtFEjzuDQufg== X-Received: by 2002:a37:ef04:: with SMTP id j4mr911920qkk.260.1602707835886; Wed, 14 Oct 2020 13:37:15 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id d142sm341968qke.125.2020.10.14.13.37.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 13:37:15 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 3/3] locale: Fix locale construct_output_path error handling Date: Wed, 14 Oct 2020 17:37:07 -0300 Message-Id: <20201014203707.2394289-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201014203707.2394289-1-adhemerval.zanella@linaro.org> References: <20201014203707.2394289-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On following localedef code: 237 output_path = construct_output_path (argv[remaining]); 238 if (output_path == NULL && ! no_archive) 239 error (4, errno, _("cannot create directory for output files")); 240 cannot_write_why = errno; The 'cannot_write_why' will be set to a non 0 value on success if euidaccess or mkdir (called by construct_output_path) change the errno on a success call. Instead o relying on the errno value regardless the previous libc call fails or not, explicit set the erro code on failure at construct_output_path. Checked on x86_64-linux-gnu. --- locale/programs/localedef.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c index b048bd05b9..4b488d5c2e 100644 --- a/locale/programs/localedef.c +++ b/locale/programs/localedef.c @@ -180,7 +180,7 @@ static struct argp argp = /* Prototypes for local functions. */ static void error_print (void); -static char *construct_output_path (char *path); +static char *construct_output_path (char *path, int *cannot_write_why); static char *normalize_codeset (const char *codeset, size_t name_len); @@ -234,10 +234,9 @@ main (int argc, char *argv[]) /* The parameter describes the output path of the constructed files. If the described files cannot be written return a NULL pointer. We don't free output_path because we will exit. */ - output_path = construct_output_path (argv[remaining]); + output_path = construct_output_path (argv[remaining], &cannot_write_why); if (output_path == NULL && ! no_archive) error (4, errno, _("cannot create directory for output files")); - cannot_write_why = errno; /* Now that the parameters are processed we have to reset the local ctype locale. (P1003.2 4.35.5.2) */ @@ -478,7 +477,7 @@ error_print (void) '/' character it is a relative path. Otherwise it names the locale this definition is for. The returned path must be freed by the caller. */ static char * -construct_output_path (char *path) +construct_output_path (char *path, int *cannot_write_why) { char *result; @@ -533,6 +532,7 @@ construct_output_path (char *path) } errno = 0; + *cannot_write_why = 0; if (no_archive && euidaccess (result, W_OK) == -1) { @@ -545,14 +545,18 @@ construct_output_path (char *path) record_verbose (stderr, _("cannot create output path \'%s\': %s"), result, strerror (errno)); + *cannot_write_why = errno; free (result); - return NULL; + result = NULL; } } else - record_verbose (stderr, - _("no write permission to output path \'%s\': %s"), - result, strerror (errno)); + { + record_verbose (stderr, + _("no write permission to output path \'%s\': %s"), + result, strerror (errno)); + *cannot_write_why = errno; + } } return result;