From b9ea935ac2e31144db8ebdc2a98ebfc3f94357cc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Sep 2021 11:05:49 +0200 Subject: Impose 16KB line length limit for regex matches in Testscript --- libbuild2/script/run.cxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 46941734..7f8fa2f 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -530,7 +530,7 @@ namespace build2 }; // Save the regex to file for troubleshooting, return the file path - // it have been saved to. + // it has been saved to. // // Note that we save the regex on line regex creation failure or if // the program output doesn't match. @@ -722,6 +722,19 @@ namespace build2 while (!s.empty () && s.back () == '\r') s.pop_back (); + // Some regex implementations (e.g., libstdc++, MSVC) are unable + // to match long strings which they "signal" by running out of + // stack or otherwise crashing instead of throwing an exception. + // So we impose some sensible limit that all of them are able to + // handle for basic expressions (e.g., [ab]+). + // + if (s.size () > 16384) + { + diag_record d (fail (ll)); + d << pr << " " << what << " lines too long to match with regex"; + output_info (d, op); + } + ls += line_char (move (s), regex.pool); } } -- cgit v1.1