From 16e67d4ebb312a838ca6be4f9b3b43ec5ea212a4 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Fri, 27 Jan 2023 20:34:24 +0100 Subject: [PATCH] Fix bug #12633 Avoid recursion when validating a macro that is defined recursively. This avoids a crash but the latex engine will choke on it, of course. --- src/mathed/InsetMathMacro.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index 1e36f5a53d..aba4ab79a0 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -988,8 +988,16 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const MathData ar(const_cast(&buffer())); MacroData const * data = buffer().getMacro(name()); if (data) { - asArray(data->definition(), ar); - ar.validate(features); + // Avoid recursion on a recursive macro definition + docstring const & def = data->definition(); + int pos = tokenPos(def, '\\', name()); + char_type c = def.at(pos + name().size()); + if (pos < 0 || (name().size() > 1 && + ((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z')))) { + asArray(def, ar); + ar.validate(features); + } } } } -- 2.39.5