Skip to content

Commit

Permalink
minor: Fix overflow in Clipsal-CMR113 and Somfy-IOHC reported by aug5t7
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Jan 24, 2022
1 parent 29b14b4 commit 2dad7b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/devices/cmr113.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Kudos to Jon Oxer for decoding this stream and putting it here:
*/

#define COMPARE_BITS 83
#define COMPARE_BYTES (COMPARE_BITS/8)
#define COMPARE_BITS 83
#define COMPARE_BYTES ((COMPARE_BITS + 7) / 8)

static int cmr113_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
Expand Down
9 changes: 5 additions & 4 deletions src/devices/somfy_iohc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ static int somfy_iohc_decode(r_device *decoder, bitbuffer_t *bitbuffer)
if (bitbuffer->num_rows != 1)
return DECODE_ABORT_EARLY;

int offset = bitbuffer_search(bitbuffer, 0, 0, preamble_pattern, 24) + 24;
if (offset >= bitbuffer->bits_per_row[0] - 19 * 10)
unsigned offset = bitbuffer_search(bitbuffer, 0, 0, preamble_pattern, 24) + 24;
if (offset + 19 * 10 >= bitbuffer->bits_per_row[0])
return DECODE_ABORT_EARLY;

int num_bits = bitbuffer->bits_per_row[0] - offset;
unsigned num_bits = bitbuffer->bits_per_row[0] - offset;
num_bits = MIN(num_bits, sizeof (b) * 8);

int len = extract_bytes_uart(bitbuffer->bb[0], offset, num_bits, b);
if (len < 19)
Expand All @@ -120,7 +121,7 @@ static int somfy_iohc_decode(r_device *decoder, bitbuffer_t *bitbuffer)
// calculate and verify checksum
if (crc16lsb(b, len, 0x8408, 0x0000) != 0) // unreflected poly 0x1021
return DECODE_FAIL_MIC;
bitrow_printf(b, len * 8, "%s: offset %d, num_bits %d, len %d, msg_len %d\n", __func__, offset, num_bits, len, msg_len);
bitrow_printf(b, len * 8, "%s: offset %u, num_bits %u, len %d, msg_len %d\n", __func__, offset, num_bits, len, msg_len);

int msg_type = (b[0]);
int dst_id = ((unsigned)b[4] << 24) | (b[3] << 16) | (b[2] << 8) | (b[1]); // assume Little-Endian
Expand Down

0 comments on commit 2dad7b9

Please sign in to comment.