From f5d6a06d2c46127e311e31132b3c0523c24c5e40 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 1 Nov 2024 00:00:13 +0100 Subject: Check for overflow --- src/work.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/work.c') diff --git a/src/work.c b/src/work.c index fe4697a..1ef699d 100644 --- a/src/work.c +++ b/src/work.c @@ -125,7 +125,10 @@ process_file(const char *locl_filename, unsigned char **locl_buf) for (;;) { ptrdiff_t want = nw + st.st_blksize; if (want > basecap) { - /* TODO: Check for overflow (top bit set) */ + if (want & (1 << (PTRDIFF_WIDTH - 1))) { + errno = EOVERFLOW; + cerr(EXIT_FATAL, "%s:", __func__); + } basecap = (ptrdiff_t)stdc_bit_ceil((size_t)want); if ((baseptr = realloc(baseptr, basecap)) == nullptr) cerr(EXIT_FATAL, "realloc:"); -- cgit v1.2.3