Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 May 2017 16:29:06 +0000 (UTC)
From:      Brooks Davis <brooks@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r318030 - stable/10/lib/libc/regex
Message-ID:  <201705091629.v49GT6Dn032374@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brooks
Date: Tue May  9 16:29:06 2017
New Revision: 318030
URL: https://svnweb.freebsd.org/changeset/base/318030

Log:
  MFC r317707:
  
  Correct an out-of-bounds read in regcomp when the RE is bad.
  
  When passed the invalid regular expression "a**", the error is
  eventually detected and seterr() is called. It sets p->error
  appropriatly and p->next and p->end to nuls which is a never used char
  nuls[10] which is zeros due to .bss initialization. Unfortunatly,
  p_ere_exp() and p_simp_re() both have fall through cases where they set
  the error, decrement p->next and access it which means a read from
  whatever .bss variable comes before nuls.
  
  Found with regex_test:repet_multi and CHERI bounds checking.
  
  Reviewed by:	ngie, pfg, emaste
  Obtained from:	CheriBSD
  Sponsored by:	DARPA, AFRL
  Differential Revision:	https://reviews.freebsd.org/D10541

Modified:
  stable/10/lib/libc/regex/regcomp.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/regex/regcomp.c
==============================================================================
--- stable/10/lib/libc/regex/regcomp.c	Tue May  9 16:27:20 2017	(r318029)
+++ stable/10/lib/libc/regex/regcomp.c	Tue May  9 16:29:06 2017	(r318030)
@@ -444,6 +444,8 @@ p_ere_exp(struct parse *p)
 		(void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
 		/* FALLTHROUGH */
 	default:
+		if (p->error != 0)
+			return;
 		p->next--;
 		wc = WGETNEXT();
 		ordinary(p, wc);
@@ -651,6 +653,8 @@ p_simp_re(struct parse *p,
 		(void)REQUIRE(starordinary, REG_BADRPT);
 		/* FALLTHROUGH */
 	default:
+		if (p->error != 0)
+			return(0);	/* Definitely not $... */
 		p->next--;
 		wc = WGETNEXT();
 		ordinary(p, wc);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705091629.v49GT6Dn032374>