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 /lib9p/srv.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 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index fc5d0f2..a4ac369 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -398,7 +398,7 @@ static void srv_respond_error(struct srv_req *req) { /* Truncate the error-string if necessary to avoid needing to * return LIB9P_ERRNO_L_ERANGE. */ if (((uint32_t)host.errstr.len) + overhead > sess->max_msg_size) - host.errstr.len = sess->max_msg_size - overhead; + host.errstr.len = (uint16_t)(sess->max_msg_size - overhead); struct lib9p_Rmsg_send_buf net; @@ -409,7 +409,7 @@ static void srv_respond_error(struct srv_req *req) { srv_msglog(req, LIB9P_TYP_Rerror, &host); r = srv_write_Rmsg(req, &net); if (r < 0) - srv_nonrespond_errorf("write: %s", net_strerror(-r)); + srv_nonrespond_errorf("write: %s", net_strerror(LM_SAFEDOWNCAST(int, -r))); } /* read coroutine *************************************************************/ @@ -421,14 +421,14 @@ static inline bool srv_read_exactly(lo_interface net_stream_conn fd, uint8_t *bu while (*done < goal) { ssize_t r = io_read(fd, &buf[*done], goal - *done); if (r < 0) { - srv_nonrespond_errorf("read: %s", net_strerror(-r)); + srv_nonrespond_errorf("read: %s", net_strerror(LM_SAFEDOWNCAST(int, -r))); return true; } else if (r == 0) { if (*done != 0) srv_nonrespond_errorf("read: unexpected EOF"); return true; } - *done += r; + *done += LM_SAFEDOWNCAST(size_t, r); } return false; } @@ -623,7 +623,7 @@ void lib9p_srv_worker(struct srv_req *ctx) { srv_respond_error(ctx); goto release; } - host_req = calloc(1, host_size); + host_req = calloc(1, LM_SAFEDOWNCAST(size_t, host_size)); assert(host_req); enum lib9p_msg_type typ; lib9p_Tmsg_unmarshal(&ctx->basectx, ctx->net_bytes, @@ -1064,7 +1064,7 @@ static void handle_Topen(struct srv_req *ctx, } if (stat.mode & LIB9P_DM_APPEND) { fidflags |= FIDFLAG_APPEND; - reqmode = reqmode & ~LIB9P_O_TRUNC; + reqmode &= LM_BITFLIP(LIB9P_O_TRUNC); } uint8_t perm_bits = 0; bool rd = false, wr = false; @@ -1277,7 +1277,7 @@ static void handle_Tread(struct srv_req *ctx, struct iovec iov; LO_CALL(fidinfo->file.io, pread, ctx, req->count, req->offset, &iov); if (!lib9p_ctx_has_error(&ctx->basectx) && !ctx->flush_acknowledged) { - resp.count = iov.iov_len; + resp.count = LM_SAFEDOWNCAST(iov.iov_len); resp.data = iov.iov_base; if (resp.count > req->count) resp.count = req->count; |