From 759529ae764842313c5e604a0b42b7911238850d Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 16 Jun 2018 00:40:14 +0000 Subject: [PATCH] PR/53368: Thomas Barabosch: Potential integer overflow in usr.bin/patch/inp.c --- usr.bin/patch/inp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index ae4611999d9a..b456bcaeb6c6 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ /* * $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $ * $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $ - * $NetBSD: inp.c,v 1.24 2015/07/24 18:56:00 christos Exp $ + * $NetBSD: inp.c,v 1.25 2018/06/16 00:40:14 christos Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__RCSID("$NetBSD: inp.c,v 1.24 2015/07/24 18:56:00 christos Exp $"); +__RCSID("$NetBSD: inp.c,v 1.25 2018/06/16 00:40:14 christos Exp $"); #include #include @@ -118,12 +118,11 @@ scan_input(const char *filename) static bool reallocate_lines(size_t *lines_allocated) { - char **p; size_t new_size; new_size = *lines_allocated * 3 / 2; - p = realloc(i_ptr, (new_size + 2) * sizeof(char *)); - if (p == NULL) { /* shucks, it was a near thing */ + int res = reallocarr(&i_ptr, new_size + 2, sizeof(char *)); + if (res != 0) { /* shucks, it was a near thing */ munmap(i_womp, i_size); i_womp = NULL; free(i_ptr); @@ -132,7 +131,6 @@ reallocate_lines(size_t *lines_allocated) return false; } *lines_allocated = new_size; - i_ptr = p; return true; }