]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
comp/zstd: make bio_zstd_read return -1 on hard errors
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Sun, 12 Oct 2025 13:39:42 +0000 (21:39 +0800)
committerTodd Short <todd.short@me.com>
Mon, 27 Oct 2025 13:39:02 +0000 (09:39 -0400)
Split NULL out param from zero outl. Return -1 on malloc failure and
NULL parameter. Keep 0 only for outl <= 0 and clean EOF. This lets
callers distinguish errors from empty reads without inspecting the
error queue.

Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/28908)

(cherry picked from commit 5871953822fb02bb651abf60dfc4a0785a5a3caa)
(cherry picked from commit ff05645178049316e5aa53d665bf5c0e05eef08c)
(cherry picked from commit 7607b9a1700ec0f2cab6b3f46ec8bfbf3d546e66)

crypto/comp/c_zstd.c

index b4667649f3ce0ce1a425d673b0b22ff4e1bd0c99..ff78d06a2524c608fa87b15271b2fb52cef5342f 100644 (file)
@@ -582,7 +582,11 @@ static int bio_zstd_read(BIO *b, char *out, int outl)
     ZSTD_outBuffer outBuf;
     BIO *next = BIO_next(b);
 
-    if (out == NULL || outl <= 0)
+    if (out == NULL) {
+        ERR_raise(ERR_LIB_COMP, ERR_R_PASSED_NULL_PARAMETER);
+        return -1;
+    }
+    if (outl <= 0)
         return 0;
 
     ctx = BIO_get_data(b);
@@ -591,7 +595,7 @@ static int bio_zstd_read(BIO *b, char *out, int outl)
         ctx->decompress.buffer = OPENSSL_malloc(ctx->decompress.bufsize);
         if (ctx->decompress.buffer == NULL) {
             ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
-            return 0;
+            return -1;
         }
         ctx->decompress.inbuf.src = ctx->decompress.buffer;
         ctx->decompress.inbuf.size = 0;