apps/x509.c: No warning reading from stdin if redirected
authorTomas Mraz <tomas@openssl.org>
Thu, 8 Feb 2024 16:19:19 +0000 (17:19 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 15 Mar 2024 08:07:51 +0000 (09:07 +0100)
Fixes #22893

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23526)

apps/x509.c
include/internal/e_os.h

index ce3fda671665fbf17037c00722f9e1606d29ed47..f77f47709a2c326e849c1684c518ed592a357374 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef OPENSSL_NO_DSA
 # include <openssl/dsa.h>
 #endif
+#include "internal/e_os.h"    /* For isatty() */
 
 #undef POSTFIX
 #define POSTFIX ".srl"
@@ -709,7 +710,7 @@ int x509_main(int argc, char **argv)
     }
 
     if (reqfile) {
-        if (infile == NULL)
+        if (infile == NULL && isatty(fileno_stdin()))
             BIO_printf(bio_err,
                        "Warning: Reading cert request from stdin since no -in option is given\n");
         req = load_csr_autofmt(infile, informat, vfyopts,
@@ -762,7 +763,7 @@ int x509_main(int argc, char **argv)
             }
         }
     } else {
-        if (infile == NULL)
+        if (infile == NULL && isatty(fileno_stdin()))
             BIO_printf(bio_err,
                        "Warning: Reading certificate from stdin since no -in or -new option is given\n");
         x = load_cert_pass(infile, informat, 1, passin, "certificate");
index d1ed62e890298c679760258431be3ab7b2c0629f..24e7a9553e2dadf795a602061b856db823050a65 100644 (file)
@@ -258,6 +258,7 @@ FILE *__iob_func(void);
 #   endif
 #   define unlink _unlink
 #   define fileno _fileno
+#   define isatty _isatty
 #  endif
 # else
 #  include <strings.h>