]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
regex: fix uninitialized memory access
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 Aug 2018 03:34:34 +0000 (20:34 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 Aug 2018 03:34:34 +0000 (20:34 -0700)
I introduced this bug into gnulib in commit
8335a4d6c7b4448cd0bcb6d0bebf1d456bcfdb17 dated 2006-04-10;
eventually it was merged into glibc.  The bug was found by
project-repo <bugs@feusi.co> and reported here:
https://lists.gnu.org/r/sed-devel/2018-08/msg00017.html
Diagnosis and draft fix reported by Assaf Gordon here:
https://lists.gnu.org/r/bug-gnulib/2018-08/msg00071.html
https://lists.gnu.org/r/bug-gnulib/2018-08/msg00142.html
* posix/regex_internal.c (build_wcs_upper_buffer):
Fix bug when mbrtowc returns 0.

ChangeLog
posix/regex_internal.c

index 67ee6ff46b155aad6feb7713ecd989c5aa16a54d..819b56f4ed0354dfa2f0a0a8d62956e35eeed02a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2018-08-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       regex: fix uninitialized memory access
+       I introduced this bug into gnulib in commit
+       8335a4d6c7b4448cd0bcb6d0bebf1d456bcfdb17 dated 2006-04-10;
+       eventually it was merged into glibc.  The bug was found by
+       project-repo <bugs@feusi.co> and reported here:
+       https://lists.gnu.org/r/sed-devel/2018-08/msg00017.html
+       Diagnosis and draft fix reported by Assaf Gordon here:
+       https://lists.gnu.org/r/bug-gnulib/2018-08/msg00071.html
+       https://lists.gnu.org/r/bug-gnulib/2018-08/msg00142.html
+       * posix/regex_internal.c (build_wcs_upper_buffer):
+       Fix bug when mbrtowc returns 0.
+
 2018-08-24  Carlos O'Donell  <carlos@redhat.com>
 
        * po/be.po: Update translation.
index 7f0083b918de6530f73937f152ae45a4a5427e42..b10588f1ccbb1992f97c617055a794f0c7c2e4d5 100644 (file)
@@ -317,7 +317,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
          mbclen = __mbrtowc (&wc,
                              ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
                               + byte_idx), remain_len, &pstr->cur_state);
-         if (BE (mbclen < (size_t) -2, 1))
+         if (BE (0 < mbclen && mbclen < (size_t) -2, 1))
            {
              wchar_t wcu = __towupper (wc);
              if (wcu != wc)
@@ -386,7 +386,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
        else
          p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
        mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
-       if (BE (mbclen < (size_t) -2, 1))
+       if (BE (0 < mbclen && mbclen < (size_t) -2, 1))
          {
            wchar_t wcu = __towupper (wc);
            if (wcu != wc)