From 8014cc11f02e51cb647255931d2212a56d556ee3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Sep 2021 09:45:31 +0200 Subject: Impose 12K line count limit for regex matches in Testscript --- libbuild2/script/run.cxx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'libbuild2/script') diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 7f8fa2f..f122ae5 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -726,7 +726,14 @@ namespace build2 // 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]+). + // handle for basic expressions (e.g., [ab]+; GCC's limits are the + // lowest, see bug 86164). See also another check (for the lines + // number) below. + // + // BTW, if we ever need to overcome this limitation (along with + // various hacks for the two-dimensional regex support), one way + // would be to factor libc++'s implementation (which doesn't seem + // to have any stack-related limits) and use it everywhere. // if (s.size () > 16384) { @@ -743,6 +750,13 @@ namespace build2 fail (ll) << "unable to read " << op << ": " << e; } + if (ls.size () > 12288) + { + diag_record d (fail (ll)); + d << pr << " " << what << " has too many lines to match with regex"; + output_info (d, op); + } + // Match the output with the regex. // // Note that we don't distinguish between the line_regex and -- cgit v1.1