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 what
ever .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
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D10541
This commit is contained in:
Brooks Davis 2017-05-02 21:20:27 +00:00
parent 517b671957
commit 9806ef7852

View File

@ -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);