BIO: prevent crash on NULL BIO for prefix_ctrl() and thus for BIO_set_prefix(), BIO_s...
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Sat, 12 Jun 2021 09:27:28 +0000 (11:27 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Tue, 15 Jun 2021 12:23:21 +0000 (14:23 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15722)

crypto/bio/bf_prefix.c

index 5727c14950e271db297ee56e111e8585c9bd41f7..c9059ca80aeb3cbbe858265fcb790883335c6696 100644 (file)
@@ -151,9 +151,9 @@ static int prefix_write(BIO *b, const char *out, size_t outl,
 static long prefix_ctrl(BIO *b, int cmd, long num, void *ptr)
 {
     long ret = 0;
-    PREFIX_CTX *ctx = BIO_get_data(b);
+    PREFIX_CTX *ctx;
 
-    if (ctx == NULL)
+    if (b == NULL || (ctx = BIO_get_data(b)) == NULL)
         return -1;
 
     switch (cmd) {