public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] Fix OOB read in stdlib thousand grouping parsing [BZ #29727]
@ 2022-11-23 14:38 Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:38 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1fb0a3690270bcf3e5eb9d978bf050bfe1261c93

commit 1fb0a3690270bcf3e5eb9d978bf050bfe1261c93
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
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.  */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [glibc/arm/morello/main] Fix OOB read in stdlib thousand grouping parsing [BZ #29727]
@ 2022-10-27 13:48 Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:48 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b6c621077438769cadebdfcc5f5298389e29081c

commit b6c621077438769cadebdfcc5f5298389e29081c
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
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.  */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-23 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 14:38 [glibc/arm/morello/main] Fix OOB read in stdlib thousand grouping parsing [BZ #29727] Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2022-10-27 13:48 Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).