From 7bfd819b39e5b7e6d830b9081d0baa28ef5bdee5 Mon Sep 17 00:00:00 2001 From: Giuseppe Congiu Date: Thu, 6 Jul 2023 15:32:22 +0200 Subject: [PATCH] sysdetect: null terminate snprintf strings for CUDA devices --- src/components/sysdetect/nvidia_gpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/sysdetect/nvidia_gpu.c b/src/components/sysdetect/nvidia_gpu.c index 71f27d861..d8f8623a1 100644 --- a/src/components/sysdetect/nvidia_gpu.c +++ b/src/components/sysdetect/nvidia_gpu.c @@ -220,6 +220,7 @@ load_cuda_sym( char *status ) if (count >= PAPI_MAX_STR_LEN) { SUBDBG("Status string truncated."); } + status[PAPI_MAX_STR_LEN - 1] = 0; return -1; } @@ -313,6 +314,7 @@ load_nvml_sym( char *status ) if (count >= PAPI_MAX_STR_LEN) { SUBDBG("Status string truncated."); } + status[PAPI_MAX_STR_LEN - 1] = 0; return -1; } @@ -371,6 +373,7 @@ open_nvidia_gpu_dev_type( _sysdetect_dev_type_info_t *dev_type_info ) if (count >= PAPI_MAX_STR_LEN) { SUBDBG("Status string truncated."); } + dev_type_info->status[PAPI_MAX_STR_LEN - 1] = 0; #endif /* HAVE_NVML */ unload_cuda_sym(); @@ -381,6 +384,7 @@ open_nvidia_gpu_dev_type( _sysdetect_dev_type_info_t *dev_type_info ) if (count >= PAPI_MAX_STR_LEN) { SUBDBG("Status string truncated."); } + dev_type_info->status[PAPI_MAX_STR_LEN - 1] = 0; #endif /* HAVE_CUDA */ }