aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2024-06-07 16:45:56 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2024-06-07 16:45:56 -0400
commit5f200ab5749a0813c48b45b217b273abeb2fdc52 (patch)
tree7cfcd2d2ee638ea98e68d3b93c14cf0eab7a5d6d /src
parent2dad0f433db9f8ec488153818ee27099fb83d398 (diff)
downloadpostgresql-5f200ab5749a0813c48b45b217b273abeb2fdc52.tar.gz
postgresql-5f200ab5749a0813c48b45b217b273abeb2fdc52.zip
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/18483-30bfff42de238000@postgresql.org
Diffstat (limited to 'src')
-rw-r--r--src/test/modules/test_predtest/test_predtest.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c
index 9c0aadd61c8..51e87f784ac 100644
--- a/src/test/modules/test_predtest/test_predtest.c
+++ b/src/test/modules/test_predtest/test_predtest.c
@@ -74,7 +74,7 @@ test_predtest(PG_FUNCTION_ARGS)
if (tupdesc->natts != 2 ||
TupleDescAttr(tupdesc, 0)->atttypid != BOOLOID ||
TupleDescAttr(tupdesc, 1)->atttypid != BOOLOID)
- elog(ERROR, "query must yield two boolean columns");
+ elog(ERROR, "test_predtest query must yield two boolean columns");
s_i_holds = w_i_holds = s_r_holds = w_r_holds = true;
for (i = 0; i < SPI_processed; i++)
@@ -124,11 +124,11 @@ test_predtest(PG_FUNCTION_ARGS)
*/
cplan = SPI_plan_get_cached_plan(spiplan);
- if (list_length(cplan->stmt_list) != 1)
- elog(ERROR, "failed to decipher query plan");
+ if (cplan == NULL || list_length(cplan->stmt_list) != 1)
+ elog(ERROR, "test_predtest query string must contain exactly one query");
stmt = linitial_node(PlannedStmt, cplan->stmt_list);
if (stmt->commandType != CMD_SELECT)
- elog(ERROR, "failed to decipher query plan");
+ elog(ERROR, "test_predtest query must be a SELECT");
plan = stmt->planTree;
Assert(list_length(plan->targetlist) >= 2);
clause1 = castNode(TargetEntry, linitial(plan->targetlist))->expr;