Message ID | 20221229125802.2715435-2-adhemerval.zanella@linaro.org |
---|---|
State | Committed |
Commit | 0b3503e2e19602db9cda47915d19a26c00f59bb1 |
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 A69E1385843A for <patchwork@sourceware.org>; Thu, 29 Dec 2022 12:58:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A69E1385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672318711; bh=OdZJwcrTC9+ew4Y8MiWGM4S18l0h3KaFtBGQksYraYM=; 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=MafuwyQOsmE3t6ubvVBxGYiyZxG+ObxzFF/n7ZUT0+gLKVG7vu9ZKy13VKK5RhHKu N0UqD7wN1v4YG8EYJ+HfgtQX02DV8v6vof7bJfOLWEG/hFhl8p+E6jlQwFHy6PM1pW gAQ5u7QwNQrnwe8EKaU/hIAvzq1Z/2Ogb6xWbvFk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id C4CDB3858D33 for <libc-alpha@sourceware.org>; Thu, 29 Dec 2022 12:58:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4CDB3858D33 Received: by mail-oi1-x236.google.com with SMTP id s187so17055366oie.10 for <libc-alpha@sourceware.org>; Thu, 29 Dec 2022 04:58:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OdZJwcrTC9+ew4Y8MiWGM4S18l0h3KaFtBGQksYraYM=; b=1ePEsF0JDy5w04bciDquE3VuojHoKXMp9oscxop+R8HVP8/6xTcb1/gitOEVTAFd4l ufmR+nQ8tp33sTruy5k+hMGsgZ5NIUcOL4JkC6rEtjW5fzRM0igF9VG8GFT6HXAG/N1z HNN4qVnoN0gCpoiXPBe0NtTJwCfZdy3Mk56OiYPgfocyzmD5Cae3rCZH+CDmIXBnzSNv ttqT94TBuq86L+LVNSDrO/UrJ7D9kOHQdg/yyDApd+hMVpFk1XutKAH/ShgK0MhZtFUs wJpX4kOpSdtv7x2ikrs3lTdJhNf59V+vT8WnWxIPPnI0cld9oZAcVa0qot0I2/+maqgi SnXg== X-Gm-Message-State: AFqh2kofRYV5ouzgip++NwLWo5FsXOm/QgD3K89ES+ZK2ap8eFmRKELs gBpyDqOfXPtoZdQbFf7rPpWYoc2xGCl2jw/eD0s= X-Google-Smtp-Source: AMrXdXtX+VP44PG/FVIGXTEPEr4yIK/D5H8+ssbiFyCqgcuZKmE4cLV6acDBsjk/n4byMxVNuXiGmQ== X-Received: by 2002:a05:6808:200d:b0:35e:823e:87a6 with SMTP id q13-20020a056808200d00b0035e823e87a6mr16812739oiw.50.1672318688672; Thu, 29 Dec 2022 04:58:08 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:dd36:4794:7acd:a716:7b01]) by smtp.gmail.com with ESMTPSA id j2-20020a9d7d82000000b0066c34486aa7sm8977378otn.73.2022.12.29.04.58.07 for <libc-alpha@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 04:58:07 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 1/4] locale: Use correct buffer size for utf8_sequence_error [BZ #19444] Date: Thu, 29 Dec 2022 09:57:59 -0300 Message-Id: <20221229125802.2715435-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221229125802.2715435-1-adhemerval.zanella@linaro.org> References: <20221229125802.2715435-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Adhemerval Zanella <adhemerval.zanella@linaro.org> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Fix remaining -Os/-O1 compile issues [BZ #19444]
|
|
Checks
Context | Check | Description |
---|---|---|
dj/TryBot-apply_patch | success | Patch applied to master at the time it was sent |
Commit Message
Adhemerval Zanella Netto
Dec. 29, 2022, 12:57 p.m. UTC
The buffer used by snprintf might not be large enough for all possible inputs, as indicated by gcc with -O1: ../locale/programs/linereader.c: In function ‘utf8_sequence_error’: ../locale/programs/linereader.c:713:58: error: ‘%02x’ directive output may be truncated writing between 2 and 8 bytes into a region of size between 1 and 13 [-Werror=format-truncation=] 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", | ^~~~ ../locale/programs/linereader.c:713:34: note: directive argument in the range [0, 2147483647] 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../locale/programs/linereader.c:713:5: note: ‘snprintf’ output between 20 and 38 bytes into a destination of size 30 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 714 | ch1, ch2, ch3, ch4); | ~~~~~~~~~~~~~~~~~~~ Checked on x86_64-linux-gnu. --- locale/programs/linereader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 12/29/22 07:57, Adhemerval Zanella via Libc-alpha wrote: > The buffer used by snprintf might not be large enough for all possible > inputs, as indicated by gcc with -O1: > > ../locale/programs/linereader.c: In function ‘utf8_sequence_error’: > ../locale/programs/linereader.c:713:58: error: ‘%02x’ directive output > may be truncated writing between 2 and 8 bytes into a region of size > between 1 and 13 [-Werror=format-truncation=] > 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", > | ^~~~ > ../locale/programs/linereader.c:713:34: note: directive argument in the > range [0, 2147483647] > 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ../locale/programs/linereader.c:713:5: note: ‘snprintf’ output between > 20 and 38 bytes into a destination of size 30 > 713 | snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x", > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 714 | ch1, ch2, ch3, ch4); > | ~~~~~~~~~~~~~~~~~~~ > > Checked on x86_64-linux-gnu. LGTM. Took me a minute to work out the 38 bytes value though. Reviewed-by: Carlos O'Donell <carlos@redhat.com> > --- > locale/programs/linereader.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/locale/programs/linereader.c b/locale/programs/linereader.c > index 0460074a0c..794f25a6e4 100644 > --- a/locale/programs/linereader.c > +++ b/locale/programs/linereader.c > @@ -701,7 +701,7 @@ static bool > utf8_sequence_error (struct linereader *lr, uint8_t ch1, int ch2, int ch3, > int ch4) > { > - char buf[30]; > + char buf[38]; OK. "0x7f 0x7fffffff 0x7fffffff 0x7fffffff\0" = 4 + 1 + 10 + 1 + 10 + 1 + 10 + 1 = 38 bytes including null terminator. I expect that at -O2 that VRP can see the values propagated from utf8_decode and determine the buffer will be smaller by a lot given the range checks. The ch2, ch3, and ch4 values shall not exceed 0xff in all cases since they are all distinct bytes in the UTF-8 sequence. I expect that the worst case is actually "0xff 0xff 0xff 0xff\0" or 20 bytes, but if the checks in utf8_decode are changed then the worst case could be 38 bytes. > > if (ch2 < 0) > snprintf (buf, sizeof (buf), "0x%02x", ch1);
diff --git a/locale/programs/linereader.c b/locale/programs/linereader.c index 0460074a0c..794f25a6e4 100644 --- a/locale/programs/linereader.c +++ b/locale/programs/linereader.c @@ -701,7 +701,7 @@ static bool utf8_sequence_error (struct linereader *lr, uint8_t ch1, int ch2, int ch3, int ch4) { - char buf[30]; + char buf[38]; if (ch2 < 0) snprintf (buf, sizeof (buf), "0x%02x", ch1);