diff options
author | Emilia Kasper <emilia@openssl.org> | 2015-09-17 20:08:48 +0200 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2015-09-17 21:45:06 +0200 |
commit | cb71f17dc786c72ec74c0ebb983b3ccfde484271 (patch) | |
tree | 100c10381cc8b083b3958b4e0634c06501fbc257 /crypto/evp | |
parent | 37faf117965de181f4de0b4032eecac2566de5f6 (diff) |
base64 decode: check for high bit
Previously, the conversion would silently coerce to ASCII. Now, we error
out.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit b785504a10310cb2872270eb409b70971be5e76e)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/encode.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/crypto/evp/encode.c b/crypto/evp/encode.c index f758a8cdf1..3005560ede 100644 --- a/crypto/evp/encode.c +++ b/crypto/evp/encode.c @@ -60,9 +60,9 @@ #include "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; |