]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kdb: Replace deprecated strcpy() with memmove() in vkdb_printf()
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 19 Aug 2025 09:59:04 +0000 (11:59 +0200)
committerDaniel Thompson (RISCstar) <danielt@kernel.org>
Sat, 20 Sep 2025 18:56:28 +0000 (19:56 +0100)
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: https://github.com/KSPP/linux/issues/88
Fixes: 5d5314d6795f ("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>
kernel/debug/kdb/kdb_io.c

index 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..b12b9db75c1d8d16dad9eea3d6fece314de21c6b 100644 (file)
@@ -714,8 +714,8 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
                 * it, depending on the results of the search.
                 */
                cp++;                /* to byte after the newline */
-               replaced_byte = *cp; /* remember what/where it was */
-               cphold = cp;
+               replaced_byte = *cp; /* remember what it was */
+               cphold = cp;         /* remember where it was */
                *cp = '\0';          /* end the string for our search */
 
                /*
@@ -732,8 +732,9 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
                         * Shift the buffer left.
                         */
                        *cphold = replaced_byte;
-                       strcpy(kdb_buffer, cphold);
-                       len = strlen(kdb_buffer);
+                       len = strlen(cphold);
+                       /* Use memmove() because the buffers overlap */
+                       memmove(kdb_buffer, cphold, len + 1);
                        next_avail = kdb_buffer + len;
                        size_avail = sizeof(kdb_buffer) - len;
                        goto kdb_print_out;
@@ -872,8 +873,9 @@ kdb_printit:
         */
        if (kdb_grepping_flag && !suspend_grep) {
                *cphold = replaced_byte;
-               strcpy(kdb_buffer, cphold);
-               len = strlen(kdb_buffer);
+               len = strlen(cphold);
+               /* Use memmove() because the buffers overlap */
+               memmove(kdb_buffer, cphold, len + 1);
                next_avail = kdb_buffer + len;
                size_avail = sizeof(kdb_buffer) - len;
        }