PR/53368: Thomas Barabosch: Potential integer overflow in usr.bin/patch/inp.c

This commit is contained in:
christos 2018-06-16 00:40:14 +00:00
parent cbd78171e7
commit 759529ae76

View File

@ -1,7 +1,7 @@
/* /*
* $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $ * $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 $ * $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 <sys/cdefs.h> #include <sys/cdefs.h>
__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 <sys/types.h> #include <sys/types.h>
#include <sys/file.h> #include <sys/file.h>
@ -118,12 +118,11 @@ scan_input(const char *filename)
static bool static bool
reallocate_lines(size_t *lines_allocated) reallocate_lines(size_t *lines_allocated)
{ {
char **p;
size_t new_size; size_t new_size;
new_size = *lines_allocated * 3 / 2; new_size = *lines_allocated * 3 / 2;
p = realloc(i_ptr, (new_size + 2) * sizeof(char *)); int res = reallocarr(&i_ptr, new_size + 2, sizeof(char *));
if (p == NULL) { /* shucks, it was a near thing */ if (res != 0) { /* shucks, it was a near thing */
munmap(i_womp, i_size); munmap(i_womp, i_size);
i_womp = NULL; i_womp = NULL;
free(i_ptr); free(i_ptr);
@ -132,7 +131,6 @@ reallocate_lines(size_t *lines_allocated)
return false; return false;
} }
*lines_allocated = new_size; *lines_allocated = new_size;
i_ptr = p;
return true; return true;
} }