From 0329d7b3209c9a6dd3b18d3fc97a5d0d33421be5 Mon Sep 17 00:00:00 2001 From: Frank Sehr Date: Tue, 18 Mar 2025 17:10:00 -0700 Subject: [PATCH] LU-18828 lnet: lnetctl SIGSEGV in infra_ping_nid Return value of strtok() not checked. Save error code and continue pinging after syntax error. Test-Parameters: trivial Signed-off-by: Frank Sehr Change-Id: I817d7c46ced9e8ea42a283b6c05dfc17ce8781f3 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58460 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lnet/utils/lnetconfig/liblnetconfig.c | 18 ++++++++++++++---- lnet/utils/lnetctl.c | 11 ++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 4a12809..af581f9 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -940,15 +940,25 @@ static int infra_ping_nid(char *ping_nids, char *src_nidstr, char *oper, first_seq = item; /* check if '-' is a part of NID, token */ - sep = strchr(token, '-'); + if (token != NULL) + sep = strchr(token, '-'); + else + sep = NULL; + if (sep == NULL) { + if (token == NULL) + id.nid = LNET_NID_ANY; + else + /* if no net is specified, + * libcfs_str2nid() will assume tcp + */ + id.nid = libcfs_str2nid(token); + id.pid = LNET_PID_ANY; - /* if no net is specified, libcfs_str2nid() will assume tcp */ - id.nid = libcfs_str2nid(token); if (id.nid == LNET_NID_ANY) { snprintf(err_str, sizeof(err_str), "\"cannot parse NID '%s'\"", - token); + token ? token : "NULL"); rc = LUSTRE_CFG_RC_BAD_PARAM; cYAML_build_error(rc, seq_no, MANAGE_CMD, oper, err_str, err_rc); diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 2700b7e4..3834721 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -5424,9 +5424,14 @@ static int jt_ping(int argc, char **argv) return rc; } - for (; optind < argc; optind++) - rc = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, -1, - &show_rc, &err_rc); + for (; optind < argc; optind++) { + int rc2; + + rc2 = lustre_lnet_ping_nid(argv[optind], src_nidstr, timeout, + -1, &show_rc, &err_rc); + if (rc2 != 0 && (rc > 0 || rc == -EOPNOTSUPP)) + rc = rc2; + } if (show_rc) cYAML_print_tree(show_rc); -- 1.8.3.1