View Issue Details

IDProjectCategoryView StatusLast Update
0000565Pgpool-IIBugpublic2020-03-06 14:56
ReporterhoshiaiAssigned Tot-ishii 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionopen 
Product Version4.1.0 
Target Version4.1.1Fixed in Version4.1.1 
Summary0000565: Segmentation falut happend by worker process
DescriptionIf apllication_name of standby's replication worker is ''(empty string), worker process of pgpool causes segment fault and this worker resatrt many times.

pgpool.log is :
2019-12-10 15:37:03: pid 16868: WARNING: worker child process with pid: 18230 was terminated by segmentation fault
2019-12-10 15:37:03: pid 16868: LOG: fork a new worker child process with pid: 18234
2019-12-10 15:37:03: pid 16868: WARNING: worker child process with pid: 18234 was terminated by segmentation fault
2019-12-10 15:37:03: pid 16868: LOG: fork a new worker child process with pid: 18238
2019-12-10 15:37:03: pid 16868: WARNING: worker child process with pid: 18238 was terminated by segmentation fault
2019-12-10 15:37:03: pid 16868: LOG: fork a new worker child process with pid: 18242
2019-12-10 15:37:03: pid 16868: WARNING: worker child process with pid: 18242 was terminated by segmentation fault
2019-12-10 15:37:03: pid 16868: LOG: fork a new worker child process with pid: 18246
2019-12-10 15:37:03: pid 16868: WARNING: worker child process with pid: 18246 was terminated by segmentation fault
2019-12-10 15:37:03: pid 16868: LOG: fork a new worker child process with pid: 18250
2019-12-10 15:37:04: pid 16868: WARNING: worker child process with pid: 18250 was terminated by segmentation fault
2019-12-10 15:37:04: pid 16868: LOG: fork a new worker child process with pid: 18254
2019-12-10 15:37:04: pid 16868: WARNING: worker child process with pid: 18254 was terminated by segmentation fault
2019-12-10 15:37:04: pid 16868: LOG: fork a new worker child process with pid: 18258
2019-12-10 15:37:04: pid 16868: WARNING: worker child process with pid: 18258 was terminated by segmentation fault
2019-12-10 15:37:04: pid 16868: LOG: fork a new worker child process with pid: 18262
2019-12-10 15:37:04: pid 16868: WARNING: worker child process with pid: 18262 was terminated by segmentation fault
2019-12-10 15:37:04: pid 16868: LOG: fork a new worker child process with pid: 18266
2019-12-10 15:37:04: pid 16868: WARNING: worker child process with pid: 18266 was terminated by segmentation fault
2019-12-10 15:37:04: pid 16868: LOG: fork a new worker child process with pid: 18270

backtrace is :
Program received signal SIGSEGV, Segmentation fault.
0x00007fdfd3c58706 in __strcmp_sse42 () from /lib64/libc.so.6
(gdb) bt
#0 0x00007fdfd3c58706 in __strcmp_sse42 () from /lib64/libc.so.6
0000001 0x000000000044f738 in check_replication_time_lag () at streaming_replication/pool_worker_child.c:404
0000002 do_worker_child () at streaming_replication/pool_worker_child.c:174
0000003 0x000000000040a0a2 in worker_fork_a_child (type=PT_WORKER, func=0x44ee40 <do_worker_child>, params=0x0) at main/pgpool_main.c:713
0000004 0x000000000040a841 in reaper () at main/pgpool_main.c:2661
0000005 0x000000000041163f in PgpoolMain (discard_status=discard_status@entry=1 '\001', clear_memcache_oidmaps=clear_memcache_oidmaps@entry=0 '\000') at main/pgpool_main.c:458
0000006 0x000000000040882a in main (argc=<optimized out>, argv=<optimized out>) at main/main.c:356


This problem is happend by strcmp() which first agument is NULL poinnter.
I think that 'application_name' col of pg_stat_replication is handled not enough.
Steps To ReproduceI tested with Pgpool 4.10 and PostgreSQL 12.1

$ pgpool_setup -n 2

$ vim data1/myrecovery.conf
#primary_conninfo = 'port=11002 user=test_usr application_name=''server1'''

#primary_conninfo = 'port=11002 user=test_usr application_name='''''

$ ./startall
TagsNo tags attached.

Activities

t-ishii

2019-12-12 17:30

developer   ~0003019

It turned out that a bug is in do_query() which is called by the worker process. When user sets an empty string to application_name, do_query() mistakenly returned NULL pointer instead of a pointer to an empty string. This means that the bug could potentially affect to all other places where do_query() gets called. So I will apply the fix to all supported branches. Patch attached. By the way, giving an empty string to application_name in primary_conninfo is not a good idea as it makes show pool_nodes returned empty replication_state | and replication_sync_state field.

do_query_fix.diff (814 bytes)
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index a4f45833..7002ff23 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -2309,7 +2309,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);
@@ -2332,7 +2332,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);
do_query_fix.diff (814 bytes)

hoshiai

2019-12-16 17:01

developer   ~0003022

Thank you for createing and commiting your patch.
I confirmed, this problem is resolved by this patch and latest V4_1_STABLE branch.

t-ishii

2019-12-19 14:25

developer   ~0003026

Thank you for confirmation. I am going to mark this as "resolved".

Issue History

Date Modified Username Field Change
2019-12-10 15:47 hoshiai New Issue
2019-12-10 16:01 hoshiai Description Updated View Revisions
2019-12-11 11:54 hoshiai Steps to Reproduce Updated View Revisions
2019-12-12 07:41 t-ishii Assigned To => t-ishii
2019-12-12 07:41 t-ishii Status new => assigned
2019-12-12 17:30 t-ishii File Added: do_query_fix.diff
2019-12-12 17:30 t-ishii Note Added: 0003019
2019-12-12 21:41 t-ishii Status assigned => feedback
2019-12-12 21:41 t-ishii Target Version => 4.1.1
2019-12-16 17:01 hoshiai Status feedback => assigned
2019-12-16 17:01 hoshiai Note Added: 0003022
2019-12-19 14:25 t-ishii Note Added: 0003026
2019-12-19 14:25 t-ishii Status assigned => resolved
2020-03-06 14:56 administrator Status resolved => closed
2020-03-06 14:56 administrator Fixed in Version => 4.1.1