From e6fc32a36bd08a9b83cfb2dac6c8bff54b10f10e Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 20 Mar 2022 11:54:43 +0100 Subject: [PATCH] shim: fix implicit conversion (check range) --- src/shim/shim.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/shim/shim.c b/src/shim/shim.c index ce05891fc..63e46446f 100644 --- a/src/shim/shim.c +++ b/src/shim/shim.c @@ -11,6 +11,7 @@ #include #include #include +#include #define DEBUG_MODULE "shim" @@ -36,7 +37,8 @@ struct shim { static bool shim_send_handler(int *err, struct mbuf *mb, void *arg) { struct shim *shim = arg; - size_t len; + int err_len; + uint16_t len; (void)shim; if (mb->pos < SHIM_HDR_SIZE) { @@ -45,7 +47,12 @@ static bool shim_send_handler(int *err, struct mbuf *mb, void *arg) return true; } - len = mbuf_get_left(mb); + err_len = try_into(len, mbuf_get_left(mb)); + if (err_len) { + DEBUG_WARNING("send: mbuf to big\n"); + *err = err_len; + return true; + } mb->pos -= SHIM_HDR_SIZE; *err = mbuf_write_u16(mb, htons(len));