Skip to content

Commit 32385c6

Browse files
committed
Avoid negative indices, especially with unsigned types
1 parent 1cd6641 commit 32385c6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libsodium/sodium/utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
742742
for (i = 0; i < blocksize; i++) {
743743
barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U)
744744
>> ((sizeof(size_t) - 1) * CHAR_BIT));
745-
tail[-i] = (tail[-i] & mask) | (0x80 & barrier_mask);
745+
*(tail - i) = ((*(tail - i)) & mask) | (0x80 & barrier_mask);
746746
mask |= barrier_mask;
747747
}
748748
return 0;
@@ -766,7 +766,7 @@ sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
766766
tail = &buf[padded_buflen - 1U];
767767

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

0 commit comments

Comments
 (0)