summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/regcomp.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2011-11-07 09:58:27 +0000
committerotto <otto@openbsd.org>2011-11-07 09:58:27 +0000
commit8434b594c8a8885350459bd55d0b6edba96134c9 (patch)
tree65e50a2737354b384da91da760ab7dc30989c436 /lib/libc/regex/regcomp.c
parentFor now turn back on the pmap PTE modification in pmap_l2ptp_ctor (diff)
downloadwireguard-openbsd-8434b594c8a8885350459bd55d0b6edba96134c9.tar.xz
wireguard-openbsd-8434b594c8a8885350459bd55d0b6edba96134c9.zip
don't handle out-of-mem conditions using compiled out asserts (ugh). From
netbsd; ok deraadt@
Diffstat (limited to 'lib/libc/regex/regcomp.c')
-rw-r--r--lib/libc/regex/regcomp.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index c94da5ec9a6..bcca6aafb8f 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: regcomp.c,v 1.20 2010/11/21 00:02:30 tedu Exp $ */
+/* $OpenBSD: regcomp.c,v 1.21 2011/11/07 09:58:27 otto Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
@@ -99,7 +99,7 @@ static sopno dupl(struct parse *, sopno, sopno);
static void doemit(struct parse *, sop, size_t);
static void doinsert(struct parse *, sop, size_t, sopno);
static void dofwd(struct parse *, sopno, sop);
-static void enlarge(struct parse *, sopno);
+static int enlarge(struct parse *, sopno);
static void stripsnug(struct parse *, struct re_guts *);
static void findmust(struct parse *, struct re_guts *);
static sopno pluscount(struct parse *, struct re_guts *);
@@ -1270,8 +1270,8 @@ dupl(struct parse *p,
assert(finish >= start);
if (len == 0)
return(ret);
- enlarge(p, p->ssize + len); /* this many unexpected additions */
- assert(p->ssize >= p->slen + len);
+ if (!enlarge(p, p->ssize + len)) /* this many unexpected additions */
+ return(ret);
(void) memcpy((char *)(p->strip + p->slen),
(char *)(p->strip + start), (size_t)len*sizeof(sop));
p->slen += len;
@@ -1297,8 +1297,8 @@ doemit(struct parse *p, sop op, size_t opnd)
/* deal with undersized strip */
if (p->slen >= p->ssize)
- enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */
- assert(p->slen < p->ssize);
+ if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */
+ return;
/* finally, it's all reduced to the easy case */
p->strip[p->slen++] = SOP(op, opnd);
@@ -1356,21 +1356,22 @@ dofwd(struct parse *p, sopno pos, sop value)
/*
- enlarge - enlarge the strip
*/
-static void
+static int
enlarge(struct parse *p, sopno size)
{
sop *sp;
if (p->ssize >= size)
- return;
+ return 1;
sp = (sop *)realloc(p->strip, size*sizeof(sop));
if (sp == NULL) {
SETERROR(REG_ESPACE);
- return;
+ return 0;
}
p->strip = sp;
p->ssize = size;
+ return 1;
}
/*