From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 57AA23853D78; Wed, 23 Nov 2022 14:38:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57AA23853D78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669214315; bh=Aup5Ljt/onC8pHilyx5iBLfOaDewR4J6OKiKDSPJ2T0=; h=From:To:Subject:Date:From; b=sBHHClDK7S5lWRS1MVx69CUKi+tNczO71UeUoNiy4fQxryp/Ys5VqBfruXsrQFjld hvih/75fDpK7kjkq49Qpvzd0zMaRHOKgnAriTfaYiHHS1Gxm21wxscEFqeQ1/eRw/a B2iKCYSTtszjbczbIo80668tYdedVoOKqLptPWHQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] Fix OOB read in stdlib thousand grouping parsing [BZ #29727] X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 5aa16bb318c542cc9a2a5b48cf90b5dd8f0873ec X-Git-Newrev: 1fb0a3690270bcf3e5eb9d978bf050bfe1261c93 Message-Id: <20221123143835.57AA23853D78@sourceware.org> Date: Wed, 23 Nov 2022 14:38:35 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1fb0a3690270bcf3e5eb9d978bf050bfe1261c93 commit 1fb0a3690270bcf3e5eb9d978bf050bfe1261c93 Author: Szabolcs Nagy Date: Tue Oct 11 15:24:41 2022 +0100 Fix OOB read in stdlib thousand grouping parsing [BZ #29727] __correctly_grouped_prefixmb only worked with thousands_len == 1, otherwise it read past the end of cp or thousands. This affects scanf formats like %'d, %'f and the internal but exposed __strto{l,ul,f,d,..}_internal with grouping flag set and an LC_NUMERIC locale where thousands_len > 1. Avoid OOB access by considering thousands_len when initializing cp. This fixes bug 29727. Found by the morello port with strict bounds checking where FAIL: stdlib/tst-strtod4 FAIL: stdlib/tst-strtod5i crashed using a locale with thousands_len==3. Diff: --- stdlib/grouping.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/grouping.c b/stdlib/grouping.c index be7922f5fd..4622897488 100644 --- a/stdlib/grouping.c +++ b/stdlib/grouping.c @@ -64,9 +64,17 @@ __correctly_grouped_prefixmb (const STRING_TYPE *begin, const STRING_TYPE *end, thousands_len = strlen (thousands); #endif +#ifdef USE_WIDE_CHAR while (end > begin) +#else + while (end - begin >= thousands_len) +#endif { +#ifdef USE_WIDE_CHAR const STRING_TYPE *cp = end - 1; +#else + const STRING_TYPE *cp = end - thousands_len; +#endif const char *gp = grouping; /* Check first group. */