From 2006a411e5186780e61e48700f3a3131c287584c Mon Sep 17 00:00:00 2001 From: Jimbo <57198431+jiabaxie@users.noreply.github.com> Date: Fri, 7 Nov 2025 15:42:56 -0500 Subject: [PATCH] SWDEV-561611 - fix codeql errors by increasing printf buffer sizes (#1507) * SWDEV-561611 - fix codeql errors by increasing printf buffer sizes * Replace sprintf with snprintf to prevent potential buffer overflow --------- Co-authored-by: cadolphe-amd --- .../tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp | 4 ++-- .../clr/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp | 4 ++-- .../clr/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp b/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp index ad79b2a1a3..d4520b5f9a 100644 --- a/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp +++ b/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfMatrixTranspose.cpp @@ -261,8 +261,8 @@ void OCLPerfMatrixTranspose::run(void) { _perfInfo = (float)perf; testDescString = ""; - char str[64]; - sprintf(str, "(%d,%d) matrix with (%2d,%2d) block size %fms (GB/s) ", width_, height_, blockSize_, + char str[90]; + snprintf(str, sizeof(str), "(%d,%d) matrix with (%2d,%2d) block size %fms (GB/s) ", width_, height_, blockSize_, blockSize_, (sec / (double)MAX_ITERATIONS) * 1000.); testDescString += str; } diff --git a/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp b/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp index 28ec411837..0b98145713 100644 --- a/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp +++ b/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfSHA256.cpp @@ -777,8 +777,8 @@ void OCLPerfSHA256::run(void) { } testDescString += "with "; - char str[40]; - sprintf(str, "%2d ip buff and %2d op buff ", num_input_buf_, num_output_buf_); + char str[45]; + snprintf(str, sizeof(str), "%2d ip buff and %2d op buff ", num_input_buf_, num_output_buf_); testDescString += str; } diff --git a/projects/clr/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp b/projects/clr/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp index 4476dc246d..517d98237d 100644 --- a/projects/clr/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp +++ b/projects/clr/opencl/tests/ocltst/module/runtime/OCLThreadTrace.cpp @@ -187,9 +187,9 @@ static void CL_CALLBACK notify_callback(const char* errinfo, const void* private static void DumpTraceSI(unsigned int index, cl_ushort* tracePtr, size_t numOfBytes) { FILE* outFile; - char file_name[16] = {0}; + char file_name[31] = {0}; static unsigned int iii = 0; - sprintf(file_name, "TTrace%d%d.out", index, iii++); + snprintf(file_name, sizeof(file_name), "TTrace%d%d.out", index, iii++); outFile = fopen(file_name, "w");