Skip to content

Commit 00ac25a

Browse files
committed
Tighten test_predtest's input checks, and improve error messages.
test_predtest() neglected to consider the possibility that SPI_plan_get_cached_plan would return NULL. This led to a core dump if the input (incorrectly) contains more than one SQL command. While here, let's expend more than zero effort on the error message for this case and nearby ones. Per (half of) bug #18483 from Alexander Kozhemyakin. Back-patch to all supported branches, not because this is very significant (it's merely test scaffolding) but to make our world a bit safer for fuzz testing. Discussion: https://postgr.es/m/[email protected]
1 parent 7ed8ce8 commit 00ac25a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/test/modules/test_predtest/test_predtest.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test_predtest(PG_FUNCTION_ARGS)
7474
if (tupdesc->natts != 2 ||
7575
TupleDescAttr(tupdesc, 0)->atttypid != BOOLOID ||
7676
TupleDescAttr(tupdesc, 1)->atttypid != BOOLOID)
77-
elog(ERROR, "query must yield two boolean columns");
77+
elog(ERROR, "test_predtest query must yield two boolean columns");
7878

7979
s_i_holds = w_i_holds = s_r_holds = w_r_holds = true;
8080
for (i = 0; i < SPI_processed; i++)
@@ -140,11 +140,11 @@ test_predtest(PG_FUNCTION_ARGS)
140140
*/
141141
cplan = SPI_plan_get_cached_plan(spiplan);
142142

143-
if (list_length(cplan->stmt_list) != 1)
144-
elog(ERROR, "failed to decipher query plan");
143+
if (cplan == NULL || list_length(cplan->stmt_list) != 1)
144+
elog(ERROR, "test_predtest query string must contain exactly one query");
145145
stmt = linitial_node(PlannedStmt, cplan->stmt_list);
146146
if (stmt->commandType != CMD_SELECT)
147-
elog(ERROR, "failed to decipher query plan");
147+
elog(ERROR, "test_predtest query must be a SELECT");
148148
plan = stmt->planTree;
149149
Assert(list_length(plan->targetlist) >= 2);
150150
clause1 = linitial_node(TargetEntry, plan->targetlist)->expr;

0 commit comments

Comments
 (0)