Skip to content

Commit

Permalink
utils: Fix invalid implicit conversion
Browse files Browse the repository at this point in the history
Which fixes a potential integer overflow in read_u32
  • Loading branch information
chouquette committed Mar 19, 2020
1 parent dcfdc23 commit 8c098f6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ static inline uint8_t *write_raw(uint8_t *p, const uint8_t *v)
static inline const uint8_t *read_u16(const uint8_t *p, size_t *s, uint16_t *v)
{
*v = 0;
*v |= *p++ << 8;
*v |= *p++ << 0;
*v |= (uint16_t)*p++ << 8;
*v |= (uint16_t)*p++ << 0;
*s -= 2;
return (p);
}

static inline const uint8_t *read_u32(const uint8_t *p, size_t *s, uint32_t *v)
{
*v = 0;
*v |= *p++ << 24;
*v |= *p++ << 16;
*v |= *p++ << 8;
*v |= *p++ << 0;
*v |= (uint32_t)*p++ << 24;
*v |= (uint32_t)*p++ << 16;
*v |= (uint32_t)*p++ << 8;
*v |= (uint32_t)*p++ << 0;
*s -= 4;
return (p);
}
Expand Down

0 comments on commit 8c098f6

Please sign in to comment.