]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
regex: fix read overrun [BZ #24114]
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 21 Jan 2019 19:08:13 +0000 (11:08 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Jan 2019 21:18:56 +0000 (13:18 -0800)
Problem found by AddressSanitizer, reported by Hongxu Chen in:
https://debbugs.gnu.org/34140
* posix/regexec.c (proceed_next_node):
Do not read past end of input buffer.

ChangeLog
posix/regexec.c

index 05e13e65f02542813b275181a856178511d3e3b9..62d732e6e7f821ca80d00aa2bf64637ece7d849d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-31  Paul Eggert  <eggert@cs.ucla.edu>
+
+       regex: fix read overrun [BZ #24114]
+       Problem found by AddressSanitizer, reported by Hongxu Chen in:
+       https://debbugs.gnu.org/34140
+       * posix/regexec.c (proceed_next_node):
+       Do not read past end of input buffer.
+
 2019-01-31  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #24059]
        (CFLAGS-wcstof_l.c): Likewise.
        (CPPFLAGS-tst-wchar-h.c): Likewise.
        (CPPFLAGS-wcstold_l.c): Likewise.
----
+
 2017-12-11  Paul A. Clarke  <pc@us.ibm.com>
 
        * sysdeps/ieee754/flt-32/s_cosf.c: New implementation.
index 91d5a797b82e2679ceab74238416de06693e46ea..084b1222d95b62eb2930166060174ef78cb74b02 100644 (file)
@@ -1293,8 +1293,10 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
              else if (naccepted)
                {
                  char *buf = (char *) re_string_get_buffer (&mctx->input);
-                 if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
-                             naccepted) != 0)
+                 if (mctx->input.valid_len - *pidx < naccepted
+                     || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
+                                 naccepted)
+                         != 0))
                    return -1;
                }
            }