summaryrefslogtreecommitdiff
path: root/lib9p/tests/testclient-sess.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-04-22 18:51:59 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-06 11:53:17 -0600
commit24e5d0ec1219e2dbb4b9510ef20833092a2b3871 (patch)
tree01bbcc34c6190fa1c35b2625e9ba1744b1447606 /lib9p/tests/testclient-sess.c
parentf09b7435b3a5222597d27238226d23ec0cbd5bd2 (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 'lib9p/tests/testclient-sess.c')
-rw-r--r--lib9p/tests/testclient-sess.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib9p/tests/testclient-sess.c b/lib9p/tests/testclient-sess.c
index 7cb7f97..3e2ba19 100644
--- a/lib9p/tests/testclient-sess.c
+++ b/lib9p/tests/testclient-sess.c
@@ -24,7 +24,7 @@ static void _send9p(int fd, struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void
bool err = lib9p_Tmsg_marshal(ctx, typ, body, &buf);
assert(!err);
size_t exp = 0;
- for (size_t i = 0; i < buf.iov_cnt; i++)
+ for (int i = 0; i < buf.iov_cnt; i++)
exp += buf.iov[i].iov_len;
ssize_t act = writev(fd, buf.iov, buf.iov_cnt);
if (act < 0)
@@ -42,7 +42,7 @@ static void _recv9p(int fd) {
ssize_t n = read(fd, &buf[done], goal-done);
if (n < 0)
error(1, errno, "read");
- done += n;
+ done += (size_t)n;
}
goal = uint32le_decode(buf);
assert(goal <= MAX_MSG_SIZE);
@@ -50,7 +50,7 @@ static void _recv9p(int fd) {
ssize_t n = read(fd, &buf[done], goal-done);
if (n < 0)
error(1, errno, "read");
- done += n;
+ done += (size_t)n;
}
}
@@ -59,7 +59,10 @@ static void _recv9p(int fd) {
int main(int argc, char *argv[]) {
if (argc != 2)
error(2, 0, "Usage: %s SERVER_PORT", argv[0]);
- uint16_t server_port = atoi(argv[1]);
+ int _server_port = atoi(argv[1]);
+ if (_server_port == 0 || _server_port > UINT16_MAX)
+ error(2, 0, "Usage: %s SERVER_PORT", argv[0]);
+ uint16_t server_port = (uint16_t)_server_port;
union {
struct sockaddr gen;