diff options
author | 2014-10-08 04:19:08 +0000 | |
---|---|---|
committer | 2014-10-08 04:19:08 +0000 | |
commit | 61867d6004213300890e3ef8be832a522ab873d6 (patch) | |
tree | 6ffda6ae4ab3398daa0a8d5fed4303c5953edd6a | |
parent | reallocarray() to detect integer overflow; ok doug (diff) | |
download | wireguard-openbsd-61867d6004213300890e3ef8be832a522ab873d6.tar.xz wireguard-openbsd-61867d6004213300890e3ef8be832a522ab873d6.zip |
add a xreallocarray() like the existing fatal xmalloc(), and use it to
detect potential integer.
ok doug
-rw-r--r-- | usr.bin/sed/compile.c | 6 | ||||
-rw-r--r-- | usr.bin/sed/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/sed/misc.c | 12 |
3 files changed, 16 insertions, 5 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index 6dffcc9c7ef..84dafe3d991 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compile.c,v 1.35 2013/11/28 18:24:55 deraadt Exp $ */ +/* $OpenBSD: compile.c,v 1.36 2014/10/08 04:19:08 deraadt Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -128,8 +128,8 @@ compile(void) *compile_stream(&prog) = NULL; fixuplabel(prog, NULL); uselabel(); - appends = xmalloc(sizeof(struct s_appends) * appendnum); - match = xmalloc((maxnsub + 1) * sizeof(regmatch_t)); + appends = xreallocarray(NULL, appendnum, sizeof(struct s_appends)); + match = xreallocarray(NULL, maxnsub + 1, sizeof(regmatch_t)); } #define EATSPACE() do { \ diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h index 51fa89bb230..7f6ae83fc9d 100644 --- a/usr.bin/sed/extern.h +++ b/usr.bin/sed/extern.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: extern.h,v 1.6 2009/08/07 03:30:56 djm Exp $*/ +/* * $OpenBSD: extern.h,v 1.7 2014/10/08 04:19:08 deraadt Exp $*/ /*- * Copyright (c) 1992 Diomidis Spinellis. * Copyright (c) 1992, 1993 @@ -53,4 +53,5 @@ int mf_fgets(SPACE *, enum e_spflag); void process(void); char *strregerror(int, regex_t *); void *xmalloc(size_t); +void *xreallocarray(void *, size_t, size_t); void *xrealloc(void *, size_t); diff --git a/usr.bin/sed/misc.c b/usr.bin/sed/misc.c index 2f5921be97c..212074a2c3e 100644 --- a/usr.bin/sed/misc.c +++ b/usr.bin/sed/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.9 2009/10/27 23:59:43 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.10 2014/10/08 04:19:08 deraadt Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -58,6 +58,16 @@ xmalloc(size_t size) return (p); } +void * +xreallocarray(void *o, size_t nmemb, size_t size) +{ + void *p; + + if ((p = reallocarray(o, nmemb, size)) == NULL) + err(FATAL, "%s", strerror(errno)); + return (p); +} + /* * realloc with result test */ |