Whamcloud - gitweb
LU-18779 lnet: lnetctl SIGSEGV in lnetctl.c getopt_internal() 22/58322/7
authorFrank Sehr <fsehr@whamcloud.com>
Thu, 6 Mar 2025 20:19:38 +0000 (12:19 -0800)
committerOleg Drokin <green@whamcloud.com>
Wed, 26 Mar 2025 03:58:20 +0000 (03:58 +0000)
Variable optindex was out of range. The whole check could be
simplified (only check optarg) if no negative values for verbose
 are expected. Also modified for peer.

Test-Parameters: trivial
Signed-off-by: Frank Sehr <fsehr@whamcloud.com>
Change-Id: I64aad7527377b098479e93040a84b0865b02de28
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58322
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Manish Regmi <mregmi@ddn.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/utils/lnetctl.c

index 88ecdde..343f269 100644 (file)
@@ -3794,13 +3794,11 @@ static int jt_show_net(int argc, char **argv)
                        network = optarg;
                        break;
                case 'v':
-                       if ((!optarg) && (argv[optind] != NULL) &&
-                           (argv[optind][0] != '-')) {
-                               if (parse_long(argv[optind++], &detail) != 0)
-                                       detail = 1;
-                       } else {
+                       /* '-v' has an optional argument. Default is 1. */
+                       if (optarg || optind >= argc ||
+                           argv[optind] == NULL || argv[optind][0] == '-' ||
+                           parse_long(argv[optind++], &detail))
                                detail = 1;
-                       }
                        break;
                case '?':
                        print_help(net_cmds, "net", "show");
@@ -5011,13 +5009,11 @@ static int jt_show_peer(int argc, char **argv)
                        nid = optarg;
                        break;
                case 'v':
-                       if ((!optarg) && (argv[optind] != NULL) &&
-                           (argv[optind][0] != '-')) {
-                               if (parse_long(argv[optind++], &detail) != 0)
-                                       detail = 1;
-                       } else {
+                       /* '-v' has an optional argument. Default is 1. */
+                       if (optarg || optind >= argc ||
+                           argv[optind] == NULL || argv[optind][0] == '-' ||
+                           parse_long(argv[optind++], &detail))
                                detail = 1;
-                       }
                        break;
                case '?':
                        print_help(peer_cmds, "peer", "show");