gdbsupport: Use xsnprintf() instead of strcat() in print-utils

Theoretically, in functions core_addr_to_string_nz() and
core_addr_to_string(), strcat() can overflow, so use a safe
approach using xsnprintf().

Change-Id: Ib9437450b3634dc35077234f462a03a8640242d4
This commit is contained in:
Aleksandar Rikalo
2025-06-20 09:08:07 +02:00
committed by Pedro Alves
parent 404285eda0
commit fcce95b68c

View File

@@ -304,8 +304,7 @@ core_addr_to_string (const CORE_ADDR addr)
{
char *str = get_print_cell ();
strcpy (str, "0x");
strcat (str, phex (addr));
xsnprintf (str, PRINT_CELL_SIZE, "0x%s", phex (addr));
return str;
}
@@ -316,8 +315,7 @@ core_addr_to_string_nz (const CORE_ADDR addr)
{
char *str = get_print_cell ();
strcpy (str, "0x");
strcat (str, phex_nz (addr));
xsnprintf (str, PRINT_CELL_SIZE, "0x%s", phex_nz (addr));
return str;
}