]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix BIO_f_asn1() to properly report some errors
authorMatt Caswell <matt@openssl.org>
Tue, 6 Dec 2022 14:35:53 +0000 (14:35 +0000)
committerTomas Mraz <tomas@openssl.org>
Thu, 22 Dec 2022 10:07:07 +0000 (11:07 +0100)
Some things that may go wrong in asn1_bio_write() are serious errors
that should be reported as -1, rather than 0 (which just means "we wrote
no data").

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19920)

crypto/asn1/bio_asn1.c

index 914d77c866c64fdd7e5ae2c2472f87b406fb9571..17b0d1aa6cad8d6ad1c4d9dbefdc8ab8781468d6 100644 (file)
@@ -172,7 +172,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
         case ASN1_STATE_START:
             if (!asn1_bio_setup_ex(b, ctx, ctx->prefix,
                                    ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER))
-                return 0;
+                return -1;
             break;
 
             /* Copy any pre data first */
@@ -189,7 +189,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
         case ASN1_STATE_HEADER:
             ctx->buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl;
             if (!ossl_assert(ctx->buflen <= ctx->bufsize))
-                return 0;
+                return -1;
             p = ctx->buf;
             ASN1_put_object(&p, 0, inl, ctx->asn1_tag, ctx->asn1_class);
             ctx->copylen = inl;