Commit 8790cc29 authored by Thorsten Blum's avatar Thorsten Blum Committed by Daniel Thompson (RISCstar)
Browse files

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: https://github.com/KSPP/linux/issues/88


Fixes: 5d5314d6 ("kdb: core for kgdb back end (1 of 2)")
Reviewed-by: default avatarDouglas Anderson <dianders@chromium.org>
Signed-off-by: default avatarThorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: default avatarDaniel Thompson (RISCstar) <danielt@kernel.org>
parent d4be3238
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -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 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
	 */
	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;
	}