From b6bc40c1048415644f202f135ec6ac81eeeed450 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Mon, 4 Dec 2023 04:42:41 -0600 Subject: [PATCH] LU-17137 utils: l_getidentity Coverity cleanup Do not assign newmod a value past the end of the allocated space. This can confuse coverity. Instead only assign valid addresses (or NULL). CoverityID: 410235 ("Memory - illegal access") Signed-off-by: Shaun Tancheff Change-Id: I767ed1273ebfab68d634b3ff22b81a4621405dd2 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53315 Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Arshad Hussain Tested-by: jenkins Tested-by: Maloo --- lustre/utils/l_getidentity.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lustre/utils/l_getidentity.c b/lustre/utils/l_getidentity.c index 34c70d8..22c93c0 100644 --- a/lustre/utils/l_getidentity.c +++ b/lustre/utils/l_getidentity.c @@ -778,9 +778,11 @@ static int lookup_db_line_nss(char *line) return -EIO; while ((tok = strtok(NULL, " \t\n")) != NULL) { - struct nss_module *newmod = g_nss_modules + g_n_nss_modules; + struct nss_module *newmod = NULL; - if (g_n_nss_modules >= NSS_MODULES_MAX_NR) + if (g_n_nss_modules < NSS_MODULES_MAX_NR) + newmod = &g_nss_modules[g_n_nss_modules]; + else return -ERANGE; if (!strcmp(tok, "files") || !strcmp(tok, "lustre")) -- 1.8.3.1