Browse Source

Merge branch 'fix-b64-zero-length-array' into develop

Closes #538
Steffen Jaeckel 1 year ago
parent
commit
7d4a646f50
1 changed files with 5 additions and 3 deletions
  1. 5 3
      src/misc/base64/base64_decode.c

+ 5 - 3
src/misc/base64/base64_decode.c

@@ -42,8 +42,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,
@@ -66,8 +66,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,
@@ -127,7 +127,9 @@ static int s_base64_decode_internal(const char *in,  unsigned long inlen,
 
    if (y != 0) {
       if (y == 1) return CRYPT_INVALID_PACKET;
-      if (((y + g) != 4) && (mode == strict) && (map != map_base64url)) return CRYPT_INVALID_PACKET;
+#if defined(LTC_BASE64)
+      if (((y + g) != 4) && (mode == strict) && (map == map_base64)) return CRYPT_INVALID_PACKET;
+#endif /* LTC_BASE64 */
       t = t << (6 * (4 - y));
       if (z + y - 1 > *outlen) return CRYPT_BUFFER_OVERFLOW;
       if (y >= 2) out[z++] = (unsigned char) ((t >> 16) & 255);