@@ -472,18 +472,30 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
472
472
if (validate_args (ctx , cnt != NULL ) < 0 )
473
473
return (-1 );
474
474
475
+ /*
476
+ * The C11 standard states that the value of a pointer is undefined
477
+ * outside of its lifetime. Since we were initilizing the argv pointer
478
+ * in two conditional blocks below, compilers that implement this
479
+ * standard clean up the local value and this causes invalid
480
+ * dereferences of the pointer when it is used later.
481
+ *
482
+ * See https://github.com/NVIDIA/libnvidia-container/issues/316 for an
483
+ * in-depth investigation.
484
+ */
485
+ 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 };
486
+ 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 };
475
487
if ((cnt -> flags & OPT_CUDA_COMPAT_MODE_LDCONFIG ) && (cnt -> cuda_compat_dir != NULL )) {
476
488
/*
477
489
* We include the cuda_compat_dir directory on the ldconfig
478
490
* command line. This ensures that the CUDA Forward compat
479
491
* libraries take precendence over the user-mode driver
480
492
* libraries in the standard library paths (libs_dir and
481
493
* libs32_dir).
482
- * * /
494
+ */
483
495
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 } ;
496
+ argv = argv_with_compat_dir ;
485
497
} 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 } ;
498
+ argv = argv_default ;
487
499
}
488
500
489
501
if (* argv [0 ] == '@' ) {
0 commit comments