diff options
author | Kurt Roeckx <kurt@roeckx.be> | 2016-06-19 14:16:16 +0200 |
---|---|---|
committer | Kurt Roeckx <kurt@roeckx.be> | 2016-06-21 20:55:54 +0200 |
commit | 01238aec4071eabf072f4e98e3fb84cbab3c7107 (patch) | |
tree | a09753990785e9f064b03d3b8181f6b7109ddcdc /crypto | |
parent | 28bd8e945ff0bf50183af2481cc36180fbccaedb (diff) |
buf2hexstr: properly deal with empty string
It wrote before the start of the string
found by afl
Reviewed-by: Richard Levitte <levitte@openssl.org>
MR: #2994
Diffstat (limited to 'crypto')
-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 29c324f474..beabec0ddc 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -198,7 +198,12 @@ char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len) const unsigned char *p; int i; - if ((tmp = OPENSSL_malloc(len * 3 + 1)) == NULL) { + if (len == 0) + { + return OPENSSL_zalloc(1); + } + + if ((tmp = OPENSSL_malloc(len * 3)) == NULL) { CRYPTOerr(CRYPTO_F_OPENSSL_BUF2HEXSTR, ERR_R_MALLOC_FAILURE); return NULL; } |