From: Yugo Nagata Date: Tue, 5 Nov 2013 01:43:44 +0000 (+0900) Subject: Fix to put null character at end of ping result string used in watchdog X-Git-Tag: V3_4_0_ALPHA1~156 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=89509dea6cc9b6461fa19806684e545f5c7b1594;p=pgpool2.git Fix to put null character at end of ping result string used in watchdog --- diff --git a/src/watchdog/wd_ping.c b/src/watchdog/wd_ping.c index 9da6705e8..2d980a802 100644 --- a/src/watchdog/wd_ping.c +++ b/src/watchdog/wd_ping.c @@ -36,6 +36,8 @@ #include "watchdog/watchdog.h" #include "watchdog/wd_ext.h" +#define WD_MAX_PING_RESULT 256 + static void * exec_ping(void * arg); static double get_result (char * ping_data); @@ -178,7 +180,7 @@ exec_ping(void * arg) char * args[8]; int pid, i = 0; int r_size = 0; - char result[256]; + char result[WD_MAX_PING_RESULT]; char ping_path[WD_MAX_PATH_LEN]; snprintf(ping_path,sizeof(ping_path),"%s/ping",pool_config->ping_path); @@ -253,10 +255,11 @@ exec_ping(void * arg) } i = 0; - while (( (r_size = read (pfd[0], &result[i], sizeof(result)-i)) > 0) && (errno == EINTR)) + while (( (r_size = read (pfd[0], &result[i], sizeof(result)-i-1)) > 0) && (errno == EINTR)) { i += r_size; } + result[sizeof(result)-1] = '\0'; close(pfd[0]); }