From 7195ea7532f4b2e05f168da823d9aed2401267cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Fri, 13 Mar 2020 19:51:02 +0100 Subject: [PATCH] Avoid regexp stack overflow in GDB string matching (bug#22149) * lisp/progmodes/gdb-mi.el (gdb--string-regexp): Swap the or-clauses so that the rarely matching one comes first. This avoids a build-up of backtrack points on the regexp stack. --- lisp/progmodes/gdb-mi.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index da5a2a503a6..c2622327967 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -1046,7 +1046,10 @@ no input, and GDB is waiting for input." (declare-function tooltip-show "tooltip" (text &optional use-echo-area)) -(defconst gdb--string-regexp "\"\\(?:[^\\\"]\\|\\\\.\\)*\"") +(defconst gdb--string-regexp (rx "\"" + (* (or (seq "\\" nonl) + (not (any "\"\\")))) + "\"")) (defun gdb-tooltip-print (expr) (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer) -- 2.39.2