Skip to content

Commit

Permalink
rr_decode: Refactor name compression
Browse files Browse the repository at this point in the history
Add an `offset` variable to store the offset instead of `len`, and fix
an implicit type conversion warning
  • Loading branch information
chouquette committed Mar 19, 2020
1 parent f0e8a72 commit 5f1e07a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ rr_decode(const uint8_t *ptr, size_t *n, const uint8_t *root, char **ss, uint8_t
const uint8_t *p;
char *buf;
size_t m;
uint16_t offset;

if (*n < sizeof(len))
if (*n < sizeof(offset))
goto err;
len &= ~0xC0;
len = (len << 8) | *ptr;
offset = ~0xC0 & len;
offset = (uint16_t)(offset << 8u) | *ptr;
advance(1);

p = root + len;
p = root + offset;
m = ptr - p + *n;
/* Avoid recursing on the same element */
if (p == orig_ptr)
Expand Down

0 comments on commit 5f1e07a

Please sign in to comment.