diff options
author | 2015-04-13 05:11:23 +0000 | |
---|---|---|
committer | 2015-04-13 05:11:23 +0000 | |
commit | 387c92ab2fdb66fc231c21acf1358113a774df17 (patch) | |
tree | 620f9504f3a312a22c66a5e6cde0372cede223f1 /usr.bin/sed/process.c | |
parent | deprecate ancient, pre-RFC4419 and undocumented (diff) | |
download | wireguard-openbsd-387c92ab2fdb66fc231c21acf1358113a774df17.tar.xz wireguard-openbsd-387c92ab2fdb66fc231c21acf1358113a774df17.zip |
correct multiplication idiom during xreallocarray, and expand appendnum
to size_t to avoid overflow after allocation success
ok guenther doug
Diffstat (limited to 'usr.bin/sed/process.c')
-rw-r--r-- | usr.bin/sed/process.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index dee318952da..12385b844a4 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process.c,v 1.21 2014/12/12 03:22:35 jsg Exp $ */ +/* $OpenBSD: process.c,v 1.22 2015/04/13 05:11:23 deraadt Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -67,7 +67,7 @@ static int substitute(struct s_command *); struct s_appends *appends; /* Array of pointers to strings to append. */ static int appendx; /* Index into appends array. */ -int appendnum; /* Size of appends array. */ +size_t appendnum; /* Size of appends array. */ static int lastaddr; /* Set by applies if last address of a range. */ static int sdone; /* If any substitutes since last line input. */ @@ -103,8 +103,8 @@ redirect: case 'a': if (appendx >= appendnum) { appends = xreallocarray(appends, - appendnum *= 2, - sizeof(struct s_appends)); + appendnum, + 2 * sizeof(struct s_appends)); appendnum *= 2; } appends[appendx].type = AP_STRING; @@ -196,10 +196,12 @@ redirect: flush_appends(); exit(0); case 'r': - if (appendx >= appendnum) + if (appendx >= appendnum) { appends = xreallocarray(appends, - appendnum *= 2, - sizeof(struct s_appends)); + appendnum, + 2 * sizeof(struct s_appends)); + appendnum *= 2; + } appends[appendx].type = AP_FILE; appends[appendx].s = cp->t; appends[appendx].len = strlen(cp->t); |