Skip to content

Commit

Permalink
shim: fix implicit conversion (check range)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Mar 21, 2022
1 parent 743bee7 commit e6fc32a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/shim/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <re_tcp.h>
#include <re_net.h>
#include <re_shim.h>
#include <re_convert.h>


#define DEBUG_MODULE "shim"
Expand All @@ -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) {
Expand All @@ -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));
Expand Down

0 comments on commit e6fc32a

Please sign in to comment.