Skip to content

Commit

Permalink
Avoid negative indices, especially with unsigned types
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Jan 3, 2019
1 parent 1cd6641 commit 32385c6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libsodium/sodium/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
for (i = 0; i < blocksize; i++) {
barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U)
>> ((sizeof(size_t) - 1) * CHAR_BIT));
tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
*(tail - i) = ((*(tail - i)) & mask) | (0x80 & barrier_mask);
mask |= barrier_mask;
}
return 0;
Expand All @@ -766,7 +766,7 @@ sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
tail = &buf[padded_buflen - 1U];

for (i = 0U; i < blocksize; i++) {
c = tail[-i];
c = *(tail - i);
is_barrier =
(( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;
acc |= c;
Expand Down

0 comments on commit 32385c6

Please sign in to comment.