From: Frank Sehr Date: Thu, 6 Mar 2025 20:19:38 +0000 (-0800) Subject: LU-18779 lnet: lnetctl SIGSEGV in lnetctl.c getopt_internal() X-Git-Tag: 2.16.54~83 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=f387535f760b9cee31e29ac05a29e071e8488e2f;p=fs%2Flustre-release.git LU-18779 lnet: lnetctl SIGSEGV in lnetctl.c getopt_internal() 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 Change-Id: I64aad7527377b098479e93040a84b0865b02de28 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58322 Reviewed-by: Oleg Drokin Reviewed-by: Cyril Bordage Reviewed-by: James Simmons Reviewed-by: Manish Regmi Tested-by: jenkins Tested-by: Maloo --- diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 88ecdde..343f269 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -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");