kdb: Fix pager search for multi-line strings
authorDaniel Thompson <daniel.thompson@linaro.org>
Wed, 9 Sep 2020 14:17:08 +0000 (15:17 +0100)
committerDaniel Thompson <daniel.thompson@linaro.org>
Thu, 1 Oct 2020 13:44:08 +0000 (14:44 +0100)
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: fb6daa7520f9d ("kdb: Provide forward search at more prompt")
Link: https://lore.kernel.org/r/20200909141708.338273-1-daniel.thompson@linaro.org
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
kernel/debug/kdb/kdb_io.c

index e7835ca88e1600ad88e31706c0e01e05a17a60f5..6735ac36b7187edb6d18c9786c0b376b90e35a57 100644 (file)
@@ -706,12 +706,16 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)
                        size_avail = sizeof(kdb_buffer) - len;
                        goto kdb_print_out;
                }
-               if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH)
+               if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) {
                        /*
                         * This was a interactive search (using '/' at more
-                        * prompt) and it has completed. Clear the flag.
+                        * prompt) and it has completed. Replace the \0 with
+                        * its original value to ensure multi-line strings
+                        * are handled properly, and return to normal mode.
                         */
+                       *cphold = replaced_byte;
                        kdb_grepping_flag = 0;
+               }
                /*
                 * at this point the string is a full line and
                 * should be printed, up to the null.