Skip to content

Commit 8790cc2

Browse files
tobluxdaniel-thompson
authored andcommitted
kdb: Replace deprecated strcpy() with memmove() in vkdb_printf()
strcpy() is deprecated and its behavior is undefined when the source and destination buffers overlap. Use memmove() instead to avoid any undefined behavior. Adjust comments for clarity. Link: KSPP#88 Fixes: 5d5314d ("kdb: core for kgdb back end (1 of 2)") Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
1 parent d4be323 commit 8790cc2

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

kernel/debug/kdb/kdb_io.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
714714
* it, depending on the results of the search.
715715
*/
716716
cp++; /* to byte after the newline */
717-
replaced_byte = *cp; /* remember what/where it was */
718-
cphold = cp;
717+
replaced_byte = *cp; /* remember what it was */
718+
cphold = cp; /* remember where it was */
719719
*cp = '\0'; /* end the string for our search */
720720

721721
/*
@@ -732,8 +732,9 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
732732
* Shift the buffer left.
733733
*/
734734
*cphold = replaced_byte;
735-
strcpy(kdb_buffer, cphold);
736-
len = strlen(kdb_buffer);
735+
len = strlen(cphold);
736+
/* Use memmove() because the buffers overlap */
737+
memmove(kdb_buffer, cphold, len + 1);
737738
next_avail = kdb_buffer + len;
738739
size_avail = sizeof(kdb_buffer) - len;
739740
goto kdb_print_out;
@@ -872,8 +873,9 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
872873
*/
873874
if (kdb_grepping_flag && !suspend_grep) {
874875
*cphold = replaced_byte;
875-
strcpy(kdb_buffer, cphold);
876-
len = strlen(kdb_buffer);
876+
len = strlen(cphold);
877+
/* Use memmove() because the buffers overlap */
878+
memmove(kdb_buffer, cphold, len + 1);
877879
next_avail = kdb_buffer + len;
878880
size_avail = sizeof(kdb_buffer) - len;
879881
}

0 commit comments

Comments
 (0)