Fix segfault in openssl app called with no args.
authorShane Lontis <shane.lontis@oracle.com>
Wed, 17 Jun 2020 23:03:32 +0000 (09:03 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Wed, 17 Jun 2020 23:03:32 +0000 (09:03 +1000)
This is a result of removal of interactive mode.
Redirected it to now use 'openssl help'.

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

apps/openssl.c
test/recipes/20-test_app.t [new file with mode: 0644]

index 7b0ccbcc092ee1cf70ede9af5788f6a30f4b3628..4c97936824ca556138ee25fbd0d64999c913b5ec 100644 (file)
@@ -308,6 +308,13 @@ int help_main(int argc, char **argv)
     char *prog;
     HELP_CHOICE o;
     DISPLAY_COLUMNS dc;
+    char *new_argv[3];
+
+    if (argc == 0) {
+        new_argv[0] = "help";
+        new_argv[1] = NULL;
+        return do_cmd(prog_init(), 1, new_argv);
+    }
 
     prog = opt_init(argc, argv, help_options);
     while ((o = opt_next()) != OPT_hEOF) {
@@ -323,8 +330,6 @@ int help_main(int argc, char **argv)
     }
 
     if (opt_num_rest() == 1) {
-        char *new_argv[3];
-
         new_argv[0] = opt_rest()[0];
         new_argv[1] = "--help";
         new_argv[2] = NULL;
diff --git a/test/recipes/20-test_app.t b/test/recipes/20-test_app.t
new file mode 100644 (file)
index 0000000..e724656
--- /dev/null
@@ -0,0 +1,25 @@
+#! /usr/bin/env perl
+# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+use strict;
+use warnings;
+
+use OpenSSL::Test;
+
+setup("test_app");
+
+plan tests => 3;
+
+ok(run(app(["openssl"])),
+   "Run openssl app with no args");
+
+ok(run(app(["openssl", "help"])),
+   "Run openssl app with help");
+
+ok(!run(app(["openssl", "-help"])),
+   "Run openssl app with incorrect arg");