Fix to put null character at end of ping result string used in watchdog
authorYugo Nagata <nagata@sraoss.co.jp>
Tue, 5 Nov 2013 01:43:44 +0000 (10:43 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Tue, 5 Nov 2013 02:17:07 +0000 (11:17 +0900)
src/watchdog/wd_ping.c

index 9da6705e89523ab760452824606884b3c9c625f3..2d980a8023f00ba5d9a7ebba0ba29a77266e4a80 100644 (file)
@@ -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]);
        }