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 <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
This commit is contained in:
Augustin Cavalier
2024-06-24 19:40:08 +00:00
committed by waddlesplash
parent 6d7e181767
commit 83e4de8b64
+9 -1
View File
@@ -1179,12 +1179,15 @@ Expression<QueryPolicy>::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<QueryPolicy>* term = NULL;
bool negated = false;
ops op = OP_NONE;
};
status_t status = B_OK;
Stack<Stack<ExpressionNode>*> exprsTree;
Stack<ExpressionNode>* currentExpr = NULL;
ExpressionNode* current = NULL;
@@ -1241,6 +1244,10 @@ Expression<QueryPolicy>::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<QueryPolicy>* equation
= new(std::nothrow) Equation<QueryPolicy>(&expr);
@@ -1255,6 +1262,7 @@ Expression<QueryPolicy>::Init(const char* expr, const char** position)
}
current->term = equation;
equations++;
}
if (!complete)
continue;