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:
committed by
waddlesplash
parent
6d7e181767
commit
83e4de8b64
@@ -1179,12 +1179,15 @@ Expression<QueryPolicy>::Init(const char* expr, const char** position)
|
|||||||
if (fTerm != NULL)
|
if (fTerm != NULL)
|
||||||
return EALREADY;
|
return EALREADY;
|
||||||
|
|
||||||
|
status_t status = B_OK;
|
||||||
|
int32 equations = 0;
|
||||||
|
const int32 kMaxEquations = 32;
|
||||||
|
|
||||||
struct ExpressionNode {
|
struct ExpressionNode {
|
||||||
Term<QueryPolicy>* term = NULL;
|
Term<QueryPolicy>* term = NULL;
|
||||||
bool negated = false;
|
bool negated = false;
|
||||||
ops op = OP_NONE;
|
ops op = OP_NONE;
|
||||||
};
|
};
|
||||||
status_t status = B_OK;
|
|
||||||
Stack<Stack<ExpressionNode>*> exprsTree;
|
Stack<Stack<ExpressionNode>*> exprsTree;
|
||||||
Stack<ExpressionNode>* currentExpr = NULL;
|
Stack<ExpressionNode>* currentExpr = NULL;
|
||||||
ExpressionNode* current = NULL;
|
ExpressionNode* current = NULL;
|
||||||
@@ -1241,6 +1244,10 @@ Expression<QueryPolicy>::Init(const char* expr, const char** position)
|
|||||||
} else if (!complete) {
|
} else if (!complete) {
|
||||||
if (current->term != NULL)
|
if (current->term != NULL)
|
||||||
break; // There already is a term.
|
break; // There already is a term.
|
||||||
|
if ((equations + 1) > kMaxEquations) {
|
||||||
|
status = E2BIG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Equation<QueryPolicy>* equation
|
Equation<QueryPolicy>* equation
|
||||||
= new(std::nothrow) Equation<QueryPolicy>(&expr);
|
= new(std::nothrow) Equation<QueryPolicy>(&expr);
|
||||||
@@ -1255,6 +1262,7 @@ Expression<QueryPolicy>::Init(const char* expr, const char** position)
|
|||||||
}
|
}
|
||||||
|
|
||||||
current->term = equation;
|
current->term = equation;
|
||||||
|
equations++;
|
||||||
}
|
}
|
||||||
if (!complete)
|
if (!complete)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user