check integer overflow for multiplication before realloc
This commit is contained in:
1 parent
8627d0c659
commit
7c0334de3d
1 file changed
+3
@@ -1,6 +1,7 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -556,6 +557,8 @@ readstdin(void)
|
|||||||
for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) {
|
for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) {
|
||||||
if (i + 1 >= itemsiz) {
|
if (i + 1 >= itemsiz) {
|
||||||
itemsiz += 256;
|
itemsiz += 256;
|
||||||
|
if (itemsiz > SIZE_MAX / sizeof(*items))
|
||||||
|
die("too many items");
|
||||||
if (!(items = realloc(items, itemsiz * sizeof(*items))))
|
if (!(items = realloc(items, itemsiz * sizeof(*items))))
|
||||||
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
|
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user