asn1: raise NOT_ENOUGH_DATA on header EOF

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)
This commit is contained in:
Joshua Rogers 2025-10-11 20:42:59 +08:00 committed by Tomas Mraz
parent 87a4607668
commit 9eb6922c59

View 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);