]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
asn1: raise NOT_ENOUGH_DATA on header EOF
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Sat, 11 Oct 2025 12:42:59 +0000 (20:42 +0800)
committerTomas Mraz <tomas@openssl.org>
Tue, 18 Nov 2025 18:29:31 +0000 (19:29 +0100)
If BIO_read returns 0 with no buffered data, raise ASN1_R_NOT_ENOUGH_DATA
so callers see a specific error instead of a generic -1.

Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28883)

crypto/asn1/a_d2i_fp.c

index 98ce023134847a5915f237caad29533a9ae66ba4..df86d8b3fe13b6c98f2d14f6267920ccd2a35479 100644 (file)
@@ -139,10 +139,12 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
                 goto err;
             }
             i = BIO_read(in, &(b->data[len]), (int)want);
-            if (i < 0 && diff == 0) {
+
+            if (i <= 0 && diff == 0) {
                 ERR_raise(ERR_LIB_ASN1, ASN1_R_NOT_ENOUGH_DATA);
                 goto err;
             }
+
             if (i > 0) {
                 if (len + i < len) {
                     ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_LONG);