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