Fix signed shift in base32 and base64 decoders.

This commit is contained in:
Dag-Erling Smørgrav 2017-12-17 16:01:32 +01:00
parent 785612b12b
commit 5768034d36
2 changed files with 4 additions and 4 deletions

View file

@ -90,7 +90,7 @@ base32_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
{
const uint8_t *in = (const uint8_t *)cin;
size_t len;
int bits, shift, padding;
unsigned int bits, shift, padding;
for (bits = shift = padding = len = 0; ilen && *in; --ilen, ++in) {
if (*in == ' ' || *in == '\t' || *in == '\r' || *in == '\n' ||
@ -119,7 +119,7 @@ base32_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
}
}
/* non-zero bits in last byte before padding */
if (shift && (bits & ~(~0 << shift)) != 0) {
if (shift && (bits & ~(~0U << shift)) != 0) {
errno = EINVAL;
return (-1);
}

View file

@ -90,7 +90,7 @@ base64_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
{
const uint8_t *in = (const uint8_t *)cin;
size_t len;
int bits, shift, padding;
unsigned int bits, shift, padding;
for (bits = shift = padding = len = 0; ilen && *in; --ilen, ++in) {
if (*in == ' ' || *in == '\t' || *in == '\r' || *in == '\n' ||
@ -119,7 +119,7 @@ base64_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
}
}
/* non-zero bits in last byte before padding */
if (shift && (bits & ~(~0 << shift)) != 0) {
if (shift && (bits & ~(~0U << shift)) != 0) {
errno = EINVAL;
return (-1);
}