From d8ab1aa427244ab260c9620c9f02516fe3d1da3d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 28 Dec 2023 13:53:02 +0100 Subject: [PATCH] Address integer overflow reported by a code analyser The output of /usr/sbin/netstat would have to be larger than 2 GB for this to be a menace. Because this seems quite improbable, address with an assert() for now. --- src/ipv4.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ipv4.c b/src/ipv4.c index 698bf108..46bfda6d 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -232,6 +232,7 @@ static int ipv4_get_route(struct rtentry *route) while (fgets(line, buffer_size - total_bytes_read - 1, fp) != NULL) { uint32_t bytes_read = strlen(line); + assert(total_bytes_read < UINT32_MAX - bytes_read); total_bytes_read += bytes_read; if (bytes_read > 0 && line[bytes_read - 1] != '\n') {