diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-09 02:50:17 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-09 02:50:17 +0000 |
commit | e7b127f9fe250993bb4f692ae0cab0bc1b7a2001 (patch) | |
tree | 4c163a1b8863c042dec3aa21544a741de869dc17 /lib/libc/regex | |
parent | 2fb8aad981cfb73b4fe1d6301dbf9329e1705eff (diff) |
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')
-rw-r--r-- | lib/libc/regex/engine.c | 10 |
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); |