Skip to content

Commit 02add5f

Browse files
committed
mca/base CID 1516779: fix possible NULL usage
In practice, this probably would never happen because we'll always have a path with a path separator in it. But we might as well be defensive and ensure to handle the case where we strtok() returns NULL on even the first call. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 98a37c9 commit 02add5f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

opal/mca/base/mca_base_component_repository.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ int mca_base_component_repository_add(const char *path)
211211
path_to_use = strdup(path);
212212

213213
dir = strtok_r(path_to_use, sep, &ctx);
214+
if (NULL == dir) {
215+
goto done;
216+
}
214217
do {
215218
if ((0 == strcmp(dir, "USER_DEFAULT") || 0 == strcmp(dir, "USR_DEFAULT"))
216219
&& NULL != mca_base_user_default_path) {
@@ -224,6 +227,7 @@ int mca_base_component_repository_add(const char *path)
224227
}
225228
} while (NULL != (dir = strtok_r(NULL, sep, &ctx)));
226229

230+
done:
227231
free(path_to_use);
228232

229233
#endif /* OPAL_HAVE_DL_SUPPORT */

0 commit comments

Comments
 (0)