From af51aea7a19c813aff257e98b11a514f48b1557e Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Tue, 16 Feb 2010 15:40:13 +0000 Subject: [PATCH] * ../src/compiler_lib/Configlet.cpp (Configlet::expand): added basic protection against infinite loops in configlet expansion. --- build_num | 2 +- doc/ChangeLog | 5 +++++ src/compiler_lib/Configlet.cpp | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/build_num b/build_num index 61f3b05e8..052f64988 100644 --- a/build_num +++ b/build_num @@ -1 +1 @@ -#define BUILD_NUM 2544 +#define BUILD_NUM 2546 diff --git a/doc/ChangeLog b/doc/ChangeLog index 453fa2f47..5bd0bbd13 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2010-02-16 vadim + + * ../src/compiler_lib/Configlet.cpp (Configlet::expand): added + basic protection against infinite loops in configlet expansion. + 2010-02-15 vadim * Added template for the OpenWRT firewall. Fixes #1237 diff --git a/src/compiler_lib/Configlet.cpp b/src/compiler_lib/Configlet.cpp index 0f655034f..8ff33dd0b 100644 --- a/src/compiler_lib/Configlet.cpp +++ b/src/compiler_lib/Configlet.cpp @@ -177,7 +177,8 @@ QString Configlet::expand() } else all_code = code.join("\n"); - while (all_code.contains(var_re)) + int counter = 0; + while (all_code.contains(var_re) && counter < 1000) { QString var = var_re.cap(1); if (vars.count(var) > 0) @@ -190,9 +191,21 @@ QString Configlet::expand() all_code.replace(QString("{{$%1}}").arg(var), QString("{{%1}}").arg(var)); } + counter++; } - while (processIf(all_code, 0)); + if (counter >= 1000) + qDebug() << QObject::tr("Configlet expansion stopped by " + "infinite loop protector. " + "Check configlet syntax. %1").arg(file_path); + + counter = 0; + while (processIf(all_code, 0) && counter < 1000) counter++; + + if (counter >= 1000) + qDebug() << QObject::tr("Configlet expansion stopped by " + "infinite loop protector. " + "Check configlet syntax. %1").arg(file_path); if (collapse_empty_strings) {