From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 8C7A43851521; Thu, 27 Oct 2022 13:48:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C7A43851521 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666878511; bh=7s1vVUpeSuC1JpvDvU46aTfStQm/tlEfYfE/FmRLksQ=; h=From:To:Subject:Date:From; b=ddFZrEzHN591vkZskAOc+o9QUNJlTBDrOvjYouOc760he5oE2D3BoOzVwK5HCanSP yxwio5AvF9kyIPCV6ODx/LXmshiSbbwyxUmsnKkZ1a/qXbxRGoSh9PpZAtrBXgXydZ iBN2dpnq50sPDcXearQVqqPxtcjON/cBH4CZBIhI= 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: 86cb990eeb22d64be6ab4c7ac3c70b507734dfd7 X-Git-Newrev: b6c621077438769cadebdfcc5f5298389e29081c Message-Id: <20221027134831.8C7A43851521@sourceware.org> Date: Thu, 27 Oct 2022 13:48:31 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b6c621077438769cadebdfcc5f5298389e29081c commit b6c621077438769cadebdfcc5f5298389e29081c 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. */