Fix psql_scan crash.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 4 Jun 2024 01:11:05 +0000 (10:11 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 4 Jun 2024 01:11:05 +0000 (10:11 +0900)
It was reported that psql_scan crashes while determining whether a
string in a long query is psql variable (i.e. starting with ":") or
not.

https://github.com/pgpool/pgpool2/issues/54

This is because callback struct were not provided while calling
psql_scan_create().  Later psql_scan() tries to invoke a callback and
crashes because the pointer to the callback struct is NULL. To fix
this, provide PsqlScanCallbacks struct with a NULL pointer inside to
the callback function. With this, psql_scan() avoids to invoke a
callback.

Backpatch to master, V4.5, V4.4, V4.3, V4.2 and V4.1 where psql_scan
was introduced.

src/protocol/pool_proto_modules.c

index 13b952163146361d33a118f41fe6f4e6d7c8182b..1684bacac4893301b7acd4fa5ce4ecf47c72ff1b 100644 (file)
@@ -4826,9 +4826,17 @@ bool multi_statement_query(char *queries)
        int             num_semicolons = 0;
        bool    done = false;
 
+       /*
+        * callback functions for our flex lexer.  need this to prevent crash when
+        * psqlscan tries to parse psql variable statements (:variable).
+        */
+       const PsqlScanCallbacks psqlscan_callbacks = {
+               NULL
+       };
+
        initPQExpBuffer(&lbuf); /* initialize line buffer */
 
-       sstate = psql_scan_create(NULL);        /* create scan state */
+       sstate = psql_scan_create(&psqlscan_callbacks); /* create scan state */
 
        /* add the query string to the scan state */
        psql_scan_setup(sstate, queries, strlen(queries), 0, true);