mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-20 02:25:14 -07:00
Avoid negative indices, especially with unsigned types
This commit is contained in:
parent
1cd6641cde
commit
32385c6b9a
@ -742,7 +742,7 @@ sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
|
|||||||
for (i = 0; i < blocksize; i++) {
|
for (i = 0; i < blocksize; i++) {
|
||||||
barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U)
|
barrier_mask = (unsigned char) (((i ^ xpadlen) - 1U)
|
||||||
>> ((sizeof(size_t) - 1) * CHAR_BIT));
|
>> ((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;
|
mask |= barrier_mask;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -766,7 +766,7 @@ sodium_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
|
|||||||
tail = &buf[padded_buflen - 1U];
|
tail = &buf[padded_buflen - 1U];
|
||||||
|
|
||||||
for (i = 0U; i < blocksize; i++) {
|
for (i = 0U; i < blocksize; i++) {
|
||||||
c = tail[-i];
|
c = *(tail - i);
|
||||||
is_barrier =
|
is_barrier =
|
||||||
(( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;
|
(( (acc - 1U) & (pad_len - 1U) & ((c ^ 0x80) - 1U) ) >> 8) & 1U;
|
||||||
acc |= c;
|
acc |= c;
|
||||||
|
Loading…
Reference in New Issue
Block a user