diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-12-07 18:25:10 +0100 |
---|---|---|
committer | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-12-10 15:19:55 +0100 |
commit | 98ba251fe6f49fc2ee310f6e559c3431922fa16d (patch) | |
tree | 2787fdf68a482df147536e9d6c1051c8289bd73e /crypto/o_str.c | |
parent | 8ca661abd78b0e0c45340100169c4b47c0290142 (diff) |
openssl_hexstr2buf_sep(): Prevent misleading 'malloc failure' errors on short input
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13614)
Diffstat (limited to 'crypto/o_str.c')
-rw-r--r-- | crypto/o_str.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c index 142ac4ba44..dbecf4841c 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -187,7 +187,12 @@ unsigned char *openssl_hexstr2buf_sep(const char *str, long *buflen, unsigned char *buf; size_t buf_n, tmp_buflen; - buf_n = strlen(str) >> 1; + buf_n = strlen(str); + if (buf_n <= 1) { + ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_HEX_STRING_TOO_SHORT); + return NULL; + } + buf_n /= 2; if ((buf = OPENSSL_malloc(buf_n)) == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return NULL; |