50f89d
commit 58559f14437d2aa71753a29fed435efa06aa4576
50f89d
Author: Paul Eggert <eggert@cs.ucla.edu>
50f89d
Date:   Tue Aug 28 21:54:28 2018 +0200
50f89d
50f89d
    regex: fix uninitialized memory access
50f89d
    
50f89d
    I introduced this bug into gnulib in commit
50f89d
    8335a4d6c7b4448cd0bcb6d0bebf1d456bcfdb17 dated 2006-04-10;
50f89d
    eventually it was merged into glibc.  The bug was found by
50f89d
    project-repo <bugs@feusi.co> and reported here:
50f89d
    https://lists.gnu.org/r/sed-devel/2018-08/msg00017.html
50f89d
    Diagnosis and draft fix reported by Assaf Gordon here:
50f89d
    https://lists.gnu.org/r/bug-gnulib/2018-08/msg00071.html
50f89d
    https://lists.gnu.org/r/bug-gnulib/2018-08/msg00142.html
50f89d
    * posix/regex_internal.c (build_wcs_upper_buffer):
50f89d
    Fix bug when mbrtowc returns 0.
50f89d
    
50f89d
    (cherry picked from commit bc680b336971305cb39896b30d72dc7101b62242)
50f89d
50f89d
diff --git a/posix/regex_internal.c b/posix/regex_internal.c
50f89d
index 7f0083b918de6530..b10588f1ccbb1992 100644
50f89d
--- a/posix/regex_internal.c
50f89d
+++ b/posix/regex_internal.c
50f89d
@@ -317,7 +317,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
50f89d
 	  mbclen = __mbrtowc (&wc,
50f89d
 			      ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
50f89d
 			       + byte_idx), remain_len, &pstr->cur_state);
50f89d
-	  if (BE (mbclen < (size_t) -2, 1))
50f89d
+	  if (BE (0 < mbclen && mbclen < (size_t) -2, 1))
50f89d
 	    {
50f89d
 	      wchar_t wcu = __towupper (wc);
50f89d
 	      if (wcu != wc)
50f89d
@@ -386,7 +386,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
50f89d
 	else
50f89d
 	  p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
50f89d
 	mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
50f89d
-	if (BE (mbclen < (size_t) -2, 1))
50f89d
+	if (BE (0 < mbclen && mbclen < (size_t) -2, 1))
50f89d
 	  {
50f89d
 	    wchar_t wcu = __towupper (wc);
50f89d
 	    if (wcu != wc)