diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:00:13 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-11-01 00:00:13 +0100 |
commit | f5d6a06d2c46127e311e31132b3c0523c24c5e40 (patch) | |
tree | 2ed6836c31f791792fa9ccbee418299fcf20d7ae | |
parent | d2b611433890d2a80b4da67374482ed6bd954e40 (diff) |
Check for overflow
-rw-r--r-- | src/work.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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:"); |