Skip to content

Commit 4769f3c

Browse files
committed
Fix pointer accessing local variable out of scope
The C11 standard states that the value of a pointer is undefined outside of its lifetime. Since we were initilizing the argv pointer in two conditional blocks, compilers that implement this standard were cleaning up the value and this caused to invalid dereferences of the pointer. The change introduces two local variables with the same lifetime of the argv pointer and assigns these in the conditional blocks instead. Signed-off-by: Evan Lezar <[email protected]>
1 parent caf057b commit 4769f3c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/nvc_ldcache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
472472
if (validate_args(ctx, cnt != NULL) < 0)
473473
return (-1);
474474

475+
char *argv_default[] = {cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
476+
char *argv_with_compat_dir[] = {cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cuda_compat_dir, cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
475477
if ((cnt->flags & OPT_CUDA_COMPAT_MODE_LDCONFIG) && (cnt->cuda_compat_dir != NULL)) {
476478
/*
477479
* We include the cuda_compat_dir directory on the ldconfig
@@ -481,9 +483,9 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
481483
* libs32_dir).
482484
* */
483485
log_info("prefering CUDA Forward Compatibility dir when running ldconfig");
484-
argv = (char * []){cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cuda_compat_dir, cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
486+
argv = argv_with_compat_dir;
485487
} else {
486-
argv = (char * []){cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
488+
argv = argv_default;
487489
}
488490

489491
if (*argv[0] == '@') {

0 commit comments

Comments
 (0)