Skip to content

Commit d081a6e

Browse files
author
Daniel Thompson
committed
kdb: Fix pager search for multi-line strings
Currently using forward search doesn't handle multi-line strings correctly. The search routine replaces line breaks with \0 during the search and, for regular searches ("help | grep Common\n"), there is code after the line has been discarded or printed to replace the break character. However during a pager search ("help\n" followed by "/Common\n") when the string is matched we will immediately return to normal output and the code that should restore the \n becomes unreachable. Fix this by restoring the replaced character when we disable the search mode and update the comment accordingly. Fixes: fb6daa7 ("kdb: Provide forward search at more prompt") Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Douglas Anderson <[email protected]> Signed-off-by: Daniel Thompson <[email protected]>
1 parent 771910f commit d081a6e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kernel/debug/kdb/kdb_io.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,16 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
706706
size_avail = sizeof(kdb_buffer) - len;
707707
goto kdb_print_out;
708708
}
709-
if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH)
709+
if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) {
710710
/*
711711
* This was a interactive search (using '/' at more
712-
* prompt) and it has completed. Clear the flag.
712+
* prompt) and it has completed. Replace the \0 with
713+
* its original value to ensure multi-line strings
714+
* are handled properly, and return to normal mode.
713715
*/
716+
*cphold = replaced_byte;
714717
kdb_grepping_flag = 0;
718+
}
715719
/*
716720
* at this point the string is a full line and
717721
* should be printed, up to the null.

0 commit comments

Comments
 (0)