Whamcloud - gitweb
LU-17137 utils: l_getidentity Coverity cleanup 15/53315/3
authorShaun Tancheff <shaun.tancheff@hpe.com>
Mon, 4 Dec 2023 10:42:41 +0000 (04:42 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 Dec 2023 01:56:13 +0000 (01:56 +0000)
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 <shaun.tancheff@hpe.com>
Change-Id: I767ed1273ebfab68d634b3ff22b81a4621405dd2
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53315
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/l_getidentity.c

index 34c70d8..22c93c0 100644 (file)
@@ -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"))