summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/engine.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2014-10-09 02:50:16 +0000
committerderaadt <deraadt@openbsd.org>2014-10-09 02:50:16 +0000
commit373c8319a991c7b16e6312d320f01a04cfae8990 (patch)
tree2dd0d5e4079bb9482079342fdfa0f7c797434057 /lib/libc/regex/engine.c
parentindent (diff)
downloadwireguard-openbsd-373c8319a991c7b16e6312d320f01a04cfae8990.tar.xz
wireguard-openbsd-373c8319a991c7b16e6312d320f01a04cfae8990.zip
use reallocarray(NULL, a, b) instead of malloc(a, b), which gives us
proper mult int overflow detection. The existing code already handles malloc failure properly, of course.
Diffstat (limited to 'lib/libc/regex/engine.c')
-rw-r--r--lib/libc/regex/engine.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c
index 687afe9bb54..95b8a8ff64b 100644
--- a/lib/libc/regex/engine.c
+++ b/lib/libc/regex/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.17 2013/11/28 05:09:45 guenther Exp $ */
+/* $OpenBSD: engine.c,v 1.18 2014/10/09 02:50:16 deraadt Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
@@ -204,8 +204,8 @@ matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[],
/* oh my, he wants the subexpressions... */
if (m->pmatch == NULL)
- m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
- sizeof(regmatch_t));
+ m->pmatch = reallocarray(NULL, m->g->nsub + 1,
+ sizeof(regmatch_t));
if (m->pmatch == NULL) {
STATETEARDOWN(m);
return(REG_ESPACE);
@@ -217,8 +217,8 @@ matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[],
dp = dissect(m, m->coldp, endp, gf, gl);
} else {
if (g->nplus > 0 && m->lastpos == NULL)
- m->lastpos = (char **)malloc((g->nplus+1) *
- sizeof(char *));
+ m->lastpos = reallocarray(NULL,
+ g->nplus+1, sizeof(char *));
if (g->nplus > 0 && m->lastpos == NULL) {
free(m->pmatch);
STATETEARDOWN(m);