]> granicus.if.org Git - openssl/commitdiff
base64 decode: check for high bit
authorEmilia Kasper <emilia@openssl.org>
Thu, 17 Sep 2015 18:08:48 +0000 (20:08 +0200)
committerEmilia Kasper <emilia@openssl.org>
Thu, 17 Sep 2015 19:42:38 +0000 (21:42 +0200)
Previously, the conversion would silently coerce to ASCII. Now, we error
out.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/evp/encode.c
test/evptests.txt

index 985fd29d8fa4f841159c8e1655b2a0d29796ddc5..36affe56261d281594a522d9ea3fb3e63b1254d7 100644 (file)
@@ -60,9 +60,9 @@
 #include "internal/cryptlib.h"
 #include <openssl/evp.h>
 
+static unsigned char conv_ascii2bin(unsigned char a);
 #ifndef CHARSET_EBCDIC
 # define conv_bin2ascii(a)       (data_bin2ascii[(a)&0x3f])
-# define conv_ascii2bin(a)       (data_ascii2bin[(a)&0x7f])
 #else
 /*
  * We assume that PEM encoded files are EBCDIC files (i.e., printable text
@@ -71,7 +71,6 @@
  * as the underlying textstring data_bin2ascii[] is already EBCDIC)
  */
 # define conv_bin2ascii(a)       (data_bin2ascii[(a)&0x3f])
-# define conv_ascii2bin(a)       (data_ascii2bin[os_toascii[a]&0x7f])
 #endif
 
 /*-
@@ -124,6 +123,23 @@ static const unsigned char data_ascii2bin[128] = {
     0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
 };
 
+#ifndef CHARSET_EBCDIC
+static unsigned char conv_ascii2bin(unsigned char a)
+{
+    if (a & 0x80)
+        return B64_ERROR;
+    return data_ascii2bin[a];
+}
+#else
+static unsigned char conv_ascii2bin(unsigned char a)
+{
+    a = os_toascii[a];
+    if (a & 0x80)
+        return B64_ERROR;
+    return data_ascii2bin[a];
+}
+#endif
+
 void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
 {
     ctx->length = 48;
index e8de2c16ecf3bc38e170f76bf483affecfc05cd8..24ef57337469e58c44345c62cf1c7929f5c14862 100644 (file)
@@ -2690,6 +2690,12 @@ Output = 61475600736247383d0a
 Encoding = invalid
 Output = 61475601736247383d0a
 
+Encoding = invalid
+Output = 61475680736247383d0a
+
+Encoding = invalid
+Output = e14756736247383d0a
+
 Encoding = canonical
 Input = "OpenSSLOpenSSL\n"
 Output = "T3BlblNTTE9wZW5TU0wK\n"