]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid NULL+X UB in bss_mem.c
authorjwalch <jeremy.walch@gmail.com>
Fri, 15 Oct 2021 23:03:17 +0000 (19:03 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 19 Oct 2021 10:16:11 +0000 (12:16 +0200)
Fixes #16816

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16818)

crypto/bio/bss_mem.c

index 7e501762bb0b3e43238960b274bb02b5032af254..9153c1f1cd8163e0c48036a21260ef660b467cd3 100644 (file)
@@ -254,7 +254,7 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
         bm = bbm->readp;
         bo = bbm->buf;
     }
-    off = bm->data - bo->data;
+    off = (bm->data == bo->data) ? 0 : bm->data - bo->data;
     remain = bm->length;
 
     switch (cmd) {
@@ -277,7 +277,7 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
         if (num < 0 || num > off + remain)
             return -1;   /* Can't see outside of the current buffer */
 
-        bm->data = bo->data + num;
+        bm->data = (num != 0) ? bo->data + num : bo->data;
         bm->length = bo->length - num;
         bm->max = bo->max - num;
         off = num;