From 83e4de8b64bae0c446e9bea492c754008e053e3c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 24 Jun 2024 15:38:26 -0400 Subject: [PATCH] file_systems/QueryParser: Limit to 32 equations maximum. This way, we won't run into stack overflow issues due to recursion. Who would really need a FS query with more than 32 equations, anyway? Fixes #18692. Change-Id: Ieda401446d9cae2e56100ddbab08bebcc724b484 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7789 Reviewed-by: waddlesplash Haiku-Format: Haiku-format Bot --- headers/private/file_systems/QueryParser.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/headers/private/file_systems/QueryParser.h b/headers/private/file_systems/QueryParser.h index 2933f0488c..5fcb90d3e6 100644 --- a/headers/private/file_systems/QueryParser.h +++ b/headers/private/file_systems/QueryParser.h @@ -1179,12 +1179,15 @@ Expression::Init(const char* expr, const char** position) if (fTerm != NULL) return EALREADY; + status_t status = B_OK; + int32 equations = 0; + const int32 kMaxEquations = 32; + struct ExpressionNode { Term* term = NULL; bool negated = false; ops op = OP_NONE; }; - status_t status = B_OK; Stack*> exprsTree; Stack* currentExpr = NULL; ExpressionNode* current = NULL; @@ -1241,6 +1244,10 @@ Expression::Init(const char* expr, const char** position) } else if (!complete) { if (current->term != NULL) break; // There already is a term. + if ((equations + 1) > kMaxEquations) { + status = E2BIG; + break; + } Equation* equation = new(std::nothrow) Equation(&expr); @@ -1255,6 +1262,7 @@ Expression::Init(const char* expr, const char** position) } current->term = equation; + equations++; } if (!complete) continue;