From c4cb84fa555ea824f5677512da997abc4c9d92cf Mon Sep 17 00:00:00 2001 From: tb <> Date: Tue, 18 Mar 2025 13:03:08 +0000 Subject: save_index: fix some code quality issues Error check BIO_new() both times it is used, drop unused j variable, Error check BIO_printf() call and turn the whole thing into single exit. Prompted by a diff by Niels Dossche ok jsing --- src/usr.bin/openssl/apps.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/usr.bin/openssl') diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index b6ceaeabb8..46197dfd49 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.71 2025/03/17 15:55:09 tb Exp $ */ +/* $OpenBSD: apps.c,v 1.72 2025/03/18 13:03:08 tb Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -1377,10 +1377,10 @@ int save_index(const char *file, const char *suffix, CA_DB *db) { char attrpath[PATH_MAX], dbfile[PATH_MAX]; - BIO *out = BIO_new(BIO_s_file()); - int j; + BIO *out; + int ret = 0; - if (out == NULL) { + if ((out = BIO_new(BIO_s_file())) == NULL) { ERR_print_errors(bio_err); goto err; } @@ -1400,28 +1400,31 @@ save_index(const char *file, const char *suffix, CA_DB *db) BIO_printf(bio_err, "unable to open '%s'\n", dbfile); goto err; } - j = TXT_DB_write(out, db->db); - if (j <= 0) + + if (TXT_DB_write(out, db->db) <= 0) goto err; BIO_free(out); - - out = BIO_new(BIO_s_file()); + if ((out = BIO_new(BIO_s_file())) == NULL) { + ERR_print_errors(bio_err); + goto err; + } if (BIO_write_filename(out, attrpath) <= 0) { perror(attrpath); BIO_printf(bio_err, "unable to open '%s'\n", attrpath); goto err; } - BIO_printf(out, "unique_subject = %s\n", - db->attributes.unique_subject ? "yes" : "no"); - BIO_free(out); + if (BIO_printf(out, "unique_subject = %s\n", + db->attributes.unique_subject ? "yes" : "no") <= 0) + goto err; - return 1; + ret = 1; err: BIO_free(out); - return 0; + + return ret; } int -- cgit v1.2.3-55-g6feb