diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-22 18:51:59 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-06 11:53:17 -0600 |
commit | 24e5d0ec1219e2dbb4b9510ef20833092a2b3871 (patch) | |
tree | 01bbcc34c6190fa1c35b2625e9ba1744b1447606 /libmisc/tests/test_obj_nest.c | |
parent | f09b7435b3a5222597d27238226d23ec0cbd5bd2 (diff) |
wip: Build with -Wconversionlukeshu/safe-conversion
I think this found a real bug in the dhcp packet parser.
I don't think anything called lib9p_str{,n}() values that could be big
enough, but their bounds-checking was broken.
Diffstat (limited to 'libmisc/tests/test_obj_nest.c')
-rw-r--r-- | libmisc/tests/test_obj_nest.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libmisc/tests/test_obj_nest.c b/libmisc/tests/test_obj_nest.c index bb9d6de..be303f2 100644 --- a/libmisc/tests/test_obj_nest.c +++ b/libmisc/tests/test_obj_nest.c @@ -5,6 +5,10 @@ */ #include <string.h> /* for memcpy() */ +#include <limits.h> /* for SSIZE_MAX, not set by newlib */ +#ifndef SSIZE_MAX +#define SSIZE_MAX (SIZE_MAX >> 1) +#endif #include <libmisc/obj.h> @@ -45,8 +49,10 @@ static ssize_t myclass_read(struct myclass *self, void *buf, size_t count) { test_assert(self); if (count > self->len) count = self->len; + if (count > SSIZE_MAX) + count = SSIZE_MAX; memcpy(buf, self->buf, count); - return count; + return (ssize_t)count; } static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) { @@ -55,9 +61,11 @@ static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) { return -1; if (count > sizeof(self->buf)) count = sizeof(self->buf); + if (count > SSIZE_MAX) + count = SSIZE_MAX; memcpy(self->buf, buf, count); self->len = count; - return count; + return (ssize_t)count; } /* main test body *************************************************************/ |