1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Handle operator-stack-overflow errors softly in tsquery and ltxtquery.

When we converted these types' input functions to report errors
through the soft-error mechanism, we missed that stack-overflow
errors can be triggered through bad user input.  Convert those
to be reported softly, too.

Bug: #19745
Reported-by: Ke <kehan5800@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19745-39cd7b93a505f9a9@postgresql.org
Backpatch-through: 16
This commit is contained in:
Tom Lane
2026-10-05 15:45:40 -04:00
parent 2509f3c6b5
commit cb600aae3a
2 changed files with 13 additions and 9 deletions

View File

@@ -247,9 +247,10 @@ makepol(QPRS_STATE *state)
}
else
{
if (lenstack == STACKDEPTH)
/* internal error */
elog(ERROR, "stack too short");
if (lenstack >= STACKDEPTH)
ereturn(state->escontext, ERR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("ltxtquery is too complex")));
stack[lenstack] = val;
lenstack++;
}
@@ -282,7 +283,6 @@ makepol(QPRS_STATE *state)
ereturn(state->escontext, ERR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
}
}
while (lenstack)

View File

@@ -633,10 +633,14 @@ typedef struct OperatorElement
} OperatorElement;
static void
pushOpStack(OperatorElement *stack, int *lenstack, int8 op, int16 distance)
pushOpStack(TSQueryParserState state,
OperatorElement *stack, int *lenstack,
int8 op, int16 distance)
{
if (*lenstack == STACKDEPTH) /* internal error */
elog(ERROR, "tsquery stack too small");
if (*lenstack >= STACKDEPTH)
ereturn(state->escontext,,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("tsquery is too complex")));
stack[*lenstack].op = op;
stack[*lenstack].distance = distance;
@@ -696,7 +700,7 @@ makepol(TSQueryParserState state,
break;
case PT_OPR:
cleanOpStack(state, opstack, &lenstack, operator);
pushOpStack(opstack, &lenstack, operator, weight);
pushOpStack(state, opstack, &lenstack, operator, weight);
break;
case PT_OPEN:
makepol(state, pushval, opaque);
@@ -714,7 +718,7 @@ makepol(TSQueryParserState state,
state->buffer)));
return;
}
/* detect soft error in pushval or recursion */
/* detect soft error in pushval, pushOpStack, or recursion */
if (SOFT_ERROR_OCCURRED(state->escontext))
return;
}