Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/regex Add some better error handling from FreeBSD, ...
details: https://anonhg.NetBSD.org/src/rev/487d52c0cd83
branches: trunk
changeset: 448722:487d52c0cd83
user: christos <christos%NetBSD.org@localhost>
date: Thu Feb 07 22:22:31 2019 +0000
description:
Add some better error handling from FreeBSD, although we don't
suffer from the same issue, since we don't decrement p->next, like
FreeBSD does because we don't have multibyte support (yet). We
choose to do this so we can fail faster and more predictably.
Here's the original FreeBSD message:
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
diffstat:
lib/libc/regex/regcomp.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diffs (36 lines):
diff -r 2729f0d20a4a -r 487d52c0cd83 lib/libc/regex/regcomp.c
--- a/lib/libc/regex/regcomp.c Thu Feb 07 22:13:52 2019 +0000
+++ b/lib/libc/regex/regcomp.c Thu Feb 07 22:22:31 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: regcomp.c,v 1.37 2019/02/07 22:13:52 christos Exp $ */
+/* $NetBSD: regcomp.c,v 1.38 2019/02/07 22:22:31 christos Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@@ -76,7 +76,7 @@
#if 0
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#else
-__RCSID("$NetBSD: regcomp.c,v 1.37 2019/02/07 22:13:52 christos Exp $");
+__RCSID("$NetBSD: regcomp.c,v 1.38 2019/02/07 22:22:31 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -474,6 +474,8 @@
REQUIRE(!MORE() || !isdigit((unsigned char)PEEK()), REG_BADRPT);
/* FALLTHROUGH */
default:
+ if (p->error != 0)
+ return;
ordinary(p, c);
break;
}
@@ -692,6 +694,8 @@
REQUIRE(starordinary, REG_BADRPT);
/* FALLTHROUGH */
default:
+ if (p->error != 0)
+ return(0);
ordinary(p, c &~ BACKSL);
break;
}
Home |
Main Index |
Thread Index |
Old Index