diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-09-13 11:05:49 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-09-13 11:05:49 +0200 |
commit | b9ea935ac2e31144db8ebdc2a98ebfc3f94357cc (patch) | |
tree | 426b517cbea70882ed967aec772667f573242d1e | |
parent | b01bac3506584402da98e874f52d8075beb145ff (diff) |
Impose 16KB line length limit for regex matches in Testscript
-rw-r--r-- | libbuild2/script/run.cxx | 15 |
1 files changed, 14 insertions, 1 deletions
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); } } |