e354a5
commit 583dd860d5b833037175247230a328f0050dbfe9
e354a5
Author: Paul Eggert <eggert@cs.ucla.edu>
e354a5
Date:   Mon Jan 21 11:08:13 2019 -0800
e354a5
e354a5
    regex: fix read overrun [BZ #24114]
e354a5
    
e354a5
    Problem found by AddressSanitizer, reported by Hongxu Chen in:
e354a5
    https://debbugs.gnu.org/34140
e354a5
    * posix/regexec.c (proceed_next_node):
e354a5
    Do not read past end of input buffer.
e354a5
e354a5
diff --git a/posix/regexec.c b/posix/regexec.c
e354a5
index 73644c2341336e66..06b8487c3e3eab0e 100644
e354a5
--- a/posix/regexec.c
e354a5
+++ b/posix/regexec.c
e354a5
@@ -1289,8 +1289,10 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
e354a5
 	      else if (naccepted)
e354a5
 		{
e354a5
 		  char *buf = (char *) re_string_get_buffer (&mctx->input);
e354a5
-		  if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
e354a5
-			      naccepted) != 0)
e354a5
+		  if (mctx->input.valid_len - *pidx < naccepted
e354a5
+		      || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
e354a5
+				  naccepted)
e354a5
+			  != 0))
e354a5
 		    return -1;
e354a5
 		}
e354a5
 	    }