public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] Fix array bounds violation in regex matcher (bug 25149)
@ 2019-11-11 11:26 Andreas Schwab
  0 siblings, 0 replies; only message in thread
From: Andreas Schwab @ 2019-11-11 11:26 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fc141ea78ee3d87c67b18488827fe2d89c9343e7

commit fc141ea78ee3d87c67b18488827fe2d89c9343e7
Author: Andreas Schwab <schwab@suse.de>
Date:   Wed Oct 30 10:38:36 2019 +0100

    Fix array bounds violation in regex matcher (bug 25149)
    
    If the regex has more subexpressions than the number of elements allocated
    in the regmatch_t array passed to regexec then proceed_next_node may
    access the regmatch_t array outside its bounds.
    
    No testcase added because even without this bug it would then crash in
    pop_fail_stack which is bug 11053.

Diff:
---
 posix/regexec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/posix/regexec.c b/posix/regexec.c
index 3c46ac8..38b6d67 100644
--- a/posix/regexec.c
+++ b/posix/regexec.c
@@ -1266,10 +1266,13 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
       if (type == OP_BACK_REF)
 	{
 	  Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
-	  naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
+	  if (subexp_idx < nregs)
+	    naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
 	  if (fs != NULL)
 	    {
-	      if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1)
+	      if (subexp_idx >= nregs
+		  || regs[subexp_idx].rm_so == -1
+		  || regs[subexp_idx].rm_eo == -1)
 		return -1;
 	      else if (naccepted)
 		{


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-11 11:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 11:26 [glibc] Fix array bounds violation in regex matcher (bug 25149) Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).