From 5628f0cb3fd2960f4a5effdf9b9d7b4bd9357713 Mon Sep 17 00:00:00 2001 From: Frederic Saunier Date: Tue, 21 Jul 2015 15:04:51 -0400 Subject: [PATCH 1/1] LU-6501 libcfs: removal last entry of libcfs_netstrfns[] Currently NID string handling test for the last entry, and last entry has .nf_type == (__u32) -1. If we ask for a non existent LND we hit the last entry which then calls a strlen on a NULL which causes a error. We can avoid this problem if we just remove the last entry since it is not used for anything except as a last entry marker. Signed-off-by: Frederic Saunier Signed-off-by: James Simmons Change-Id: Ia8e3bea0f01bb5fa78e88bfbca698b0aa0d148ea Reviewed-on: http://review.whamcloud.com/15424 Tested-by: Jenkins Reviewed-by: frank zago Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- libcfs/libcfs/util/nidstrings.c | 11 +++-------- lnet/lnet/nidstrings.c | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/libcfs/libcfs/util/nidstrings.c b/libcfs/libcfs/util/nidstrings.c index b150a0d..b52d041 100644 --- a/libcfs/libcfs/util/nidstrings.c +++ b/libcfs/libcfs/util/nidstrings.c @@ -459,8 +459,6 @@ static struct netstrfns libcfs_netstrfns[] = { /* .nf_match_addr*/ cfs_ip_addr_match, /* .nf_is_contiguous */ cfs_ip_is_contiguous, /* .nf_min_max */ cfs_ip_min_max}, - /* placeholder for net0 alias. It MUST BE THE LAST ENTRY */ - {/* .nf_type */ -1}, }; static const size_t libcfs_nnetstrfns = @@ -486,8 +484,7 @@ libcfs_namenum2netstrfns(const char *name) for (i = 0; i < libcfs_nnetstrfns; i++) { nf = &libcfs_netstrfns[i]; - if (nf->nf_type >= 0 && - !strncmp(name, nf->nf_name, strlen(nf->nf_name))) + if (!strncmp(name, nf->nf_name, strlen(nf->nf_name))) return nf; } return NULL; @@ -499,8 +496,7 @@ libcfs_name2netstrfns(const char *name) int i; for (i = 0; i < libcfs_nnetstrfns; i++) - if (libcfs_netstrfns[i].nf_type >= 0 && - !strcmp(libcfs_netstrfns[i].nf_name, name)) + if (!strcmp(libcfs_netstrfns[i].nf_name, name)) return &libcfs_netstrfns[i]; return NULL; @@ -607,8 +603,7 @@ libcfs_str2net_internal(const char *str, __u32 *net) for (i = 0; i < libcfs_nnetstrfns; i++) { nf = &libcfs_netstrfns[i]; - if (nf->nf_type >= 0 && - !strncmp(str, nf->nf_name, strlen(nf->nf_name))) + if (!strncmp(str, nf->nf_name, strlen(nf->nf_name))) break; } diff --git a/lnet/lnet/nidstrings.c b/lnet/lnet/nidstrings.c index b43f46d..8f7808d 100644 --- a/lnet/lnet/nidstrings.c +++ b/lnet/lnet/nidstrings.c @@ -1116,8 +1116,6 @@ static struct netstrfns libcfs_netstrfns[] = { /* .nf_match_addr*/ cfs_ip_addr_match, /* .nf_is_contiguous */ cfs_ip_is_contiguous, /* .nf_min_max */ cfs_ip_min_max}, - /* placeholder for net0 alias. It MUST BE THE LAST ENTRY */ - {/* .nf_type */ -1}, }; static const size_t libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns); @@ -1142,8 +1140,7 @@ libcfs_namenum2netstrfns(const char *name) for (i = 0; i < libcfs_nnetstrfns; i++) { nf = &libcfs_netstrfns[i]; - if (nf->nf_type >= 0 && - !strncmp(name, nf->nf_name, strlen(nf->nf_name))) + if (!strncmp(name, nf->nf_name, strlen(nf->nf_name))) return nf; } return NULL; @@ -1155,8 +1152,7 @@ libcfs_name2netstrfns(const char *name) int i; for (i = 0; i < libcfs_nnetstrfns; i++) - if (libcfs_netstrfns[i].nf_type >= 0 && - !strcmp(libcfs_netstrfns[i].nf_name, name)) + if (!strcmp(libcfs_netstrfns[i].nf_name, name)) return &libcfs_netstrfns[i]; return NULL; @@ -1269,8 +1265,7 @@ libcfs_str2net_internal(const char *str, __u32 *net) for (i = 0; i < libcfs_nnetstrfns; i++) { nf = &libcfs_netstrfns[i]; - if (nf->nf_type >= 0 && - !strncmp(str, nf->nf_name, strlen(nf->nf_name))) + if (!strncmp(str, nf->nf_name, strlen(nf->nf_name))) break; } -- 1.8.3.1