Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

EDAC/ghes: Replace deprecated strcpy() in ghes_edac_report_mem_error()

strcpy() has been deprecated¹ because it performs no bounds checking on the
destination buffer, which can lead to buffer overflows. Use the safer
strscpy() instead.

¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Link: https://patch.msgid.link/20251118135621.101148-2-thorsten.blum@linux.dev

authored by

Thorsten Blum and committed by
Borislav Petkov (AMD)
cdf5ecc3 f18e71cd

+4 -3
+4 -3
drivers/edac/ghes_edac.c
··· 15 15 #include "edac_module.h" 16 16 #include <ras/ras_event.h> 17 17 #include <linux/notifier.h> 18 + #include <linux/string.h> 18 19 19 20 #define OTHER_DETAIL_LEN 400 20 21 ··· 333 332 p = pvt->msg; 334 333 p += snprintf(p, sizeof(pvt->msg), "%s", cper_mem_err_type_str(etype)); 335 334 } else { 336 - strcpy(pvt->msg, "unknown error"); 335 + strscpy(pvt->msg, "unknown error"); 337 336 } 338 337 339 338 /* Error address */ ··· 358 357 dimm = find_dimm_by_handle(mci, mem_err->mem_dev_handle); 359 358 if (dimm) { 360 359 e->top_layer = dimm->idx; 361 - strcpy(e->label, dimm->label); 360 + strscpy(e->label, dimm->label); 362 361 } 363 362 } 364 363 if (p > e->location) 365 364 *(p - 1) = '\0'; 366 365 367 366 if (!*e->label) 368 - strcpy(e->label, "unknown memory"); 367 + strscpy(e->label, "unknown memory"); 369 368 370 369 /* All other fields are mapped on e->other_detail */ 371 370 p = pvt->other_detail;