[SWDEV-533349] codeQL erors in amdsmi source code (#588)
Signed-off-by: Saeed, Oosman <Oosman.Saeed@amd.com>
This commit is contained in:
@@ -1233,8 +1233,8 @@ int main() {
|
||||
uint64_t mem = 0, gtt_mem = 0, cpu_mem = 0, vram_mem = 0;
|
||||
uint64_t gfx = 0, enc = 0;
|
||||
uint32_t cu_occupancy = 0;
|
||||
char bdf_str[20];
|
||||
sprintf(bdf_str, "%04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32,
|
||||
char bdf_str[64] = {0};
|
||||
snprintf(bdf_str, sizeof(bdf_str), "%04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32,
|
||||
static_cast<uint64_t>(bdf.domain_number),
|
||||
static_cast<uint32_t>(bdf.bus_number),
|
||||
static_cast<uint32_t>(bdf.device_number),
|
||||
@@ -1265,7 +1265,7 @@ int main() {
|
||||
struct passwd *pwd = nullptr;
|
||||
struct stat st;
|
||||
|
||||
sprintf(command, "/proc/%d", process_info_list[it].pid);
|
||||
snprintf(command, sizeof(command), "/proc/%d", process_info_list[it].pid);
|
||||
if (stat(command, &st))
|
||||
continue;
|
||||
pwd = getpwuid(st.st_uid);
|
||||
|
||||
@@ -7360,9 +7360,14 @@ rsmi_event_notification_get(int timeout_ms,
|
||||
* Both event are expressed in hex.
|
||||
* information is a string
|
||||
*/
|
||||
char message[MAX_EVENT_NOTIFICATION_MSG_SIZE];
|
||||
char message[MAX_EVENT_NOTIFICATION_MSG_SIZE] = {0};
|
||||
// parse the line here for event_number and rest of message_information
|
||||
sscanf(event_in, "%x %[^\n]\n", &event, message);
|
||||
// sscanf(event_in, "%x %[^\n]\n", &event, message); // This is unsafe code and flagged by codeql. Replace with iss below:
|
||||
std::istringstream iss(event_in);
|
||||
iss >> std::hex >> event;
|
||||
std::string message_str;
|
||||
std::getline(iss >> std::ws, message_str);
|
||||
snprintf(message, sizeof(message), "%s", message_str.c_str());
|
||||
|
||||
// parse message based on event received
|
||||
switch (event){
|
||||
|
||||
@@ -414,7 +414,7 @@ amdsmi_status_t amdsmi_get_socket_info(
|
||||
amdsmi_status_t amdsmi_get_processor_info(
|
||||
amdsmi_processor_handle processor_handle,
|
||||
size_t len, char *name) {
|
||||
char proc_id[10];
|
||||
char proc_id[16] = {0};
|
||||
AMDSMI_CHECK_INIT();
|
||||
|
||||
if (processor_handle == nullptr || name == nullptr) {
|
||||
@@ -426,7 +426,7 @@ amdsmi_status_t amdsmi_get_processor_info(
|
||||
.handle_to_processor(processor_handle, &processor);
|
||||
if (r != AMDSMI_STATUS_SUCCESS) return r;
|
||||
|
||||
sprintf(proc_id, "%d", processor->get_processor_index());
|
||||
snprintf(proc_id, sizeof(proc_id), "%d", processor->get_processor_index());
|
||||
strncpy(name, proc_id, len);
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user