CORE: Fix small bug in passphrase caching
authorRichard Levitte <levitte@openssl.org>
Fri, 28 Aug 2020 11:07:35 +0000 (13:07 +0200)
committerRichard Levitte <levitte@openssl.org>
Thu, 3 Sep 2020 15:48:32 +0000 (17:48 +0200)
Passphrase caching didn't allocate memory when it got to cache an
empty string, leading to a crash.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12587)

crypto/passphrase.c

index ac352697db3f2178f17e04d15d0d7eaeff2d4d93..170374f9d9cf2ed6a184695632ffa877394f389a 100644 (file)
@@ -273,7 +273,8 @@ int ossl_pw_get_passphrase(char *pass, size_t pass_size, size_t *pass_len,
 
  do_cache:
     if (ret && data->flag_cache_passphrase) {
-        if (*pass_len > data->cached_passphrase_len) {
+        if (data->cached_passphrase == NULL
+            || *pass_len > data->cached_passphrase_len) {
             void *new_cache =
                 OPENSSL_clear_realloc(data->cached_passphrase,
                                       data->cached_passphrase_len,