From 55b7fa2609e1fe354517a745b78182323bce24ed Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Tue, 14 Jun 2022 10:39:47 +0200 Subject: [PATCH] Have set_dateopt() return 1 on success to make -dateopt work Fixes #18553 Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18554) (cherry picked from commit 67e1b558e67a3bee1f20f8a9e067211b440404f8) --- apps/lib/apps.c | 4 +++- test/recipes/25-test_x509.t | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/lib/apps.c b/apps/lib/apps.c index a7ac4368efe..16161964b0f 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -1148,7 +1148,9 @@ int set_dateopt(unsigned long *dateopt, const char *arg) *dateopt = ASN1_DTFLGS_RFC822; else if (OPENSSL_strcasecmp(arg, "iso_8601") == 0) *dateopt = ASN1_DTFLGS_ISO8601; - return 0; + else + return 0; + return 1; } int set_ext_copy(int *copy_type, const char *arg) diff --git a/test/recipes/25-test_x509.t b/test/recipes/25-test_x509.t index 81bd8f6f6e8..67abee10281 100644 --- a/test/recipes/25-test_x509.t +++ b/test/recipes/25-test_x509.t @@ -16,7 +16,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/; setup("test_x509"); -plan tests => 18; +plan tests => 21; # Prevent MSys2 filename munging for arguments that look like file paths but # aren't @@ -135,3 +135,14 @@ SKIP: { ok(test_errors("Unable to load Public Key", "sm2.pem", '-text'), "error loading unsupported sm2 cert"); } + +# 3 tests for -dateopts formats +ok(run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "rfc_822", + "-in", srctop_file("test/certs", "ca-cert.pem")])), + "Run with rfc_8222 -dateopt format"); +ok(run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "iso_8601", + "-in", srctop_file("test/certs", "ca-cert.pem")])), + "Run with iso_8601 -dateopt format"); +ok(!run(app(["openssl", "x509", "-noout", "-dates", "-dateopt", "invalid_format", + "-in", srctop_file("test/certs", "ca-cert.pem")])), + "Run with invalid -dateopt format"); -- 2.47.2