Fix replication delay worker segfault when application_name is an empty string.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 12 Dec 2019 07:33:18 +0000 (16:33 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 12 Dec 2019 09:18:10 +0000 (18:18 +0900)
The process calls do_query() to obtain the query result against
pg_stat_replication_view.  If user sets application_name to an empty
string, the result data row packet length will be 0. However
do_query() did not consider the length == 0 case, which resulted in
giving NULL pointer to strcmp() which is called from the worker
process. That means the bug is not specific to this case (a new
feature added in Pgpool-II 4.1) but it potentially affects many other
places where do_query() gets called, although it had not been reported
in the field. So this fix should be applied to all supported branches.

Per bug 565.

src/protocol/pool_process_query.c

index def37ae30144c195c66c01dba27d6b7130d3b8ff..f99c1ce4c83355e58df5d2509f63688e056bd6d1 100644 (file)
@@ -2395,7 +2395,7 @@ do_query(POOL_CONNECTION * backend, char *query, POOL_SELECT_RESULT * *result, i
 
                                                        res->nullflags[num_data] = len;
 
-                                                       if (len > 0)    /* NOT NULL? */
+                                                       if (len >= 0)   /* NOT NULL? */
                                                        {
                                                                res->data[num_data] = palloc(len + 1);
                                                                memcpy(res->data[num_data], p, len);
@@ -2418,7 +2418,7 @@ do_query(POOL_CONNECTION * backend, char *query, POOL_SELECT_RESULT * *result, i
 
                                                                res->nullflags[num_data] = len;
 
-                                                               if (len > 0)
+                                                               if (len >= 0)
                                                                {
                                                                        p = pool_read2(backend, len);
                                                                        res->data[num_data] = palloc(len + 1);