From e98ddc9553a5f48886401da8bf07d3465c30c1e0 Mon Sep 17 00:00:00 2001 From: "okbob@github.com" Date: Mon, 5 Aug 2024 10:05:58 +0200 Subject: [PATCH] fix anonymous function has not set hashkey, and then should not be searched in plpgsql_check_HashTable. Anonymous block should be always marked as unchecked. Fix crash #175 --- expected/plpgsql_check_passive.out | 6 ++++++ expected/plpgsql_check_passive_1.out | 6 ++++++ sql/plpgsql_check_passive.sql | 7 +++++++ src/check_function.c | 3 +++ 4 files changed, 22 insertions(+) diff --git a/expected/plpgsql_check_passive.out b/expected/plpgsql_check_passive.out index dbbc7d2..473a3c2 100644 --- a/expected/plpgsql_check_passive.out +++ b/expected/plpgsql_check_passive.out @@ -353,3 +353,9 @@ end; $$ language plpgsql; call proc_test(); drop procedure proc_test(); +-- should not to crash +set plpgsql_check.mode = 'fresh_start'; +do $$ +begin +end; +$$; diff --git a/expected/plpgsql_check_passive_1.out b/expected/plpgsql_check_passive_1.out index 31f45c9..d9c9b6e 100644 --- a/expected/plpgsql_check_passive_1.out +++ b/expected/plpgsql_check_passive_1.out @@ -350,3 +350,9 @@ end; $$ language plpgsql; call proc_test(); drop procedure proc_test(); +-- should not to crash +set plpgsql_check.mode = 'fresh_start'; +do $$ +begin +end; +$$; diff --git a/sql/plpgsql_check_passive.sql b/sql/plpgsql_check_passive.sql index 094a52e..f627802 100644 --- a/sql/plpgsql_check_passive.sql +++ b/sql/plpgsql_check_passive.sql @@ -325,3 +325,10 @@ $$ language plpgsql; call proc_test(); drop procedure proc_test(); + +-- should not to crash +set plpgsql_check.mode = 'fresh_start'; +do $$ +begin +end; +$$; diff --git a/src/check_function.c b/src/check_function.c index 5be61b7..c0a2427 100644 --- a/src/check_function.c +++ b/src/check_function.c @@ -1375,6 +1375,9 @@ plpgsql_check_is_checked(PLpgSQL_function *func) { plpgsql_check_HashEnt *hentry; + if (!func->fn_hashkey) + return false; + hentry = (plpgsql_check_HashEnt *) hash_search(plpgsql_check_HashTable, (void *) func->fn_hashkey, HASH_FIND,