Removed dead code in linebuffer_ctrl()
authorTomas Mraz <tomas@openssl.org>
Mon, 19 Apr 2021 13:34:59 +0000 (15:34 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 22 Apr 2021 14:45:57 +0000 (16:45 +0200)
Fixes Coverity CID 1476284

Also add possible number truncation check.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14928)

crypto/bio/bf_lbuf.c

index e9b946fe872971818f43e959966a58c8364b9eb7..946ff0d23b22ec1c1441dc832fb619a3c086e866 100644 (file)
@@ -232,12 +232,12 @@ static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
         }
         break;
     case BIO_C_SET_BUFF_SIZE:
+        if (num > INT_MAX)
+            return 0;
         obs = (int)num;
         p = ctx->obuf;
         if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
-            if (num <= 0)
-                return 0;
-            p = OPENSSL_malloc((size_t)num);
+            p = OPENSSL_malloc((size_t)obs);
             if (p == NULL)
                 goto malloc_error;
         }