openssl spkac: Fix reading SPKAC data from stdin
authorTomas Mraz <tomas@openssl.org>
Wed, 2 Jun 2021 15:01:41 +0000 (17:01 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 3 Jun 2021 16:07:56 +0000 (18:07 +0200)
Fixes #15367

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15593)

apps/lib/apps.c

index 3d6588ba23ed30d74f42452b232879d7b6b02e2e..8604c752517098d817827d3ad20c2d132834ca53 100644 (file)
@@ -404,14 +404,18 @@ CONF *app_load_config_verbose(const char *filename, int verbose)
 
 CONF *app_load_config_internal(const char *filename, int quiet)
 {
-    BIO *in = NULL; /* leads to empty config in case filename == "" */
+    BIO *in;
     CONF *conf;
 
-    if (*filename != '\0'
-        && (in = bio_open_default_(filename, 'r', FORMAT_TEXT, quiet)) == NULL)
-        return NULL;
-    conf = app_load_config_bio(in, filename);
-    BIO_free(in);
+    if (filename == NULL || *filename != '\0') {
+        if ((in = bio_open_default_(filename, 'r', FORMAT_TEXT, quiet)) == NULL)
+            return NULL;
+        conf = app_load_config_bio(in, filename);
+        BIO_free(in);
+    } else {
+        /* Return empty config if filename is empty string. */
+        conf = NCONF_new_ex(app_libctx, NULL);
+    }
     return conf;
 }