From 9b2017de0ca8e917262dfca4a8a4e81de1190717 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Mon, 28 Feb 2022 15:29:23 -0500 Subject: [PATCH] Prevent stack buffer overflow readlink() does not append a null byte to buffer. Initialize the tpath to prevent stack buffer overflow. Change-Id: I17895dc3576b080a0c35bd0528a5b83223ec1c1b [ROCm/rocm_smi_lib commit: 4b65b0307fbfb4aaccf3ad7eb834f082141f6f16] --- projects/rocm-smi-lib/src/rocm_smi_main.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/rocm-smi-lib/src/rocm_smi_main.cc b/projects/rocm-smi-lib/src/rocm_smi_main.cc index 171fc9d803..18bf121e1f 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_main.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_main.cc @@ -183,6 +183,7 @@ static uint32_t ConstructBDFID(std::string path, uint64_t *bdfid) { assert(bdfid != nullptr); char tpath[256]; ssize_t ret; + memset(tpath,0,256); ret = readlink(path.c_str(), tpath, 256);