Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid zero length array with LTC_BASE64_URL unset #538

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/misc/base64/base64_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static const unsigned char map_base64[256] = {
255, 255, 255, 255 };
#endif /* LTC_BASE64 */

static const unsigned char map_base64url[] = {
#if defined(LTC_BASE64_URL)
static const unsigned char map_base64url[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 253, 253, 255,
255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 253, 255, 255, 255,
Expand All @@ -72,8 +72,8 @@ static const unsigned char map_base64url[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255
#endif /* LTC_BASE64_URL */
};
#endif /* LTC_BASE64_URL */

enum {
insane = 0,
Expand Down Expand Up @@ -132,8 +132,14 @@ static int _base64_decode_internal(const char *in, unsigned long inlen,
}

if (y != 0) {
int allow_b64url = 0;
#ifdef LTC_BASE64_URL
if (map == map_base64url) {
allow_b64url = 1;
}
#endif
if (y == 1) return CRYPT_INVALID_PACKET;
if (((y + g) != 4) && (mode == strict) && (map != map_base64url)) return CRYPT_INVALID_PACKET;
if (((y + g) != 4) && (mode == strict) && (!allow_b64url)) return CRYPT_INVALID_PACKET;
t = t << (6 * (4 - y));
if (z + y - 1 > *outlen) return CRYPT_BUFFER_OVERFLOW;
if (y >= 2) out[z++] = (unsigned char) ((t >> 16) & 255);
Expand Down