From e3f0362407f6f40e413d6dcb35888514dbaed6f8 Mon Sep 17 00:00:00 2001 From: Peiwei Hu Date: Mon, 15 Nov 2021 00:41:21 +0800 Subject: [PATCH] BIO_read_filename: fix return check Reviewed-by: Matt Caswell Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/17033) --- ssl/ssl_cert.c | 4 ++-- test/sslapitest.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index a9e71046b3..e77b6ec097 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -625,7 +625,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file_ex(const char *file, ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE); goto err; } - if (!BIO_read_filename(in, file)) + if (BIO_read_filename(in, file) <= 0) goto err; /* Internally lh_X509_NAME_retrieve() needs the libctx to retrieve SHA1 */ @@ -696,7 +696,7 @@ int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, goto err; } - if (!BIO_read_filename(in, file)) + if (BIO_read_filename(in, file) <= 0) goto err; for (;;) { diff --git a/test/sslapitest.c b/test/sslapitest.c index b06d5d7a14..00f27cb78e 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -7994,7 +7994,7 @@ static int cert_cb(SSL *s, void *arg) if (!TEST_ptr(chain)) goto out; if (!TEST_ptr(in = BIO_new(BIO_s_file())) - || !TEST_int_ge(BIO_read_filename(in, rootfile), 0) + || !TEST_int_gt(BIO_read_filename(in, rootfile), 0) || !TEST_ptr(rootx = X509_new_ex(libctx, NULL)) || !TEST_ptr(PEM_read_bio_X509(in, &rootx, NULL, NULL)) || !TEST_true(sk_X509_push(chain, rootx))) @@ -8002,13 +8002,13 @@ static int cert_cb(SSL *s, void *arg) rootx = NULL; BIO_free(in); if (!TEST_ptr(in = BIO_new(BIO_s_file())) - || !TEST_int_ge(BIO_read_filename(in, ecdsacert), 0) + || !TEST_int_gt(BIO_read_filename(in, ecdsacert), 0) || !TEST_ptr(x509 = X509_new_ex(libctx, NULL)) || !TEST_ptr(PEM_read_bio_X509(in, &x509, NULL, NULL))) goto out; BIO_free(in); if (!TEST_ptr(in = BIO_new(BIO_s_file())) - || !TEST_int_ge(BIO_read_filename(in, ecdsakey), 0) + || !TEST_int_gt(BIO_read_filename(in, ecdsakey), 0) || !TEST_ptr(pkey = PEM_read_bio_PrivateKey_ex(in, NULL, NULL, NULL, libctx, NULL))) -- 2.34.1