2
0
mirror of https://github.com/gchq/CyberChef synced 2026-01-06 02:23:20 +00:00

Regexes are now checked for 0-length matches and incremented manually to avoid infinite loops

This commit is contained in:
n1474335
2018-01-10 19:44:25 +00:00
parent 56551712d6
commit ec02b7deda
3 changed files with 15 additions and 3 deletions

View File

@@ -29,6 +29,11 @@ const Extract = {
match;
while ((match = searchRegex.exec(input))) {
// Moves pointer when an empty string is matched (prevents infinite loop)
if (match.index === searchRegex.lastIndex) {
searchRegex.lastIndex++;
}
if (removeRegex && removeRegex.test(match[0]))
continue;
total++;

View File

@@ -208,6 +208,11 @@ const Regex = {
total = 0;
while ((m = regex.exec(input))) {
// Moves pointer when an empty string is matched (prevents infinite loop)
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// Add up to match
output += Utils.escapeHtml(input.slice(i, m.index));
@@ -248,6 +253,11 @@ const Regex = {
match;
while ((match = regex.exec(input))) {
// Moves pointer when an empty string is matched (prevents infinite loop)
if (match.index === regex.lastIndex) {
regex.lastIndex++;
}
total++;
if (matches) {
output += match[0] + "\n";