From faca84a590158ff827a3db06e6ec1fc0f75930e2 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 19 Oct 2017 09:50:44 +0200 Subject: [PATCH] Fix GCC 7 string truncation warning, too small temporary buffer In GCC 7 the -Wall infers the new -Wformat-truncation which finds problems with string truncation in functions like snprintf(). This patch fixes a problem in condition parsing for very long PID filenames which might be truncated in internal buffers causing a mismatch in Finit condition tracking. Signed-off-by: Joachim Nilsson --- plugins/pidfile.c | 4 ++-- src/svc.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index 073f47c5..330b4a7d 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -46,7 +46,7 @@ static char *mkcond(char *buf, size_t len, char *nm) static void pidfile_callback(void *arg, int fd, int events) { static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1]; - static char cond[MAX_ARG_LEN]; + static char cond[MAX_COND_LEN]; struct inotify_event *ev; ssize_t sz, len; @@ -94,7 +94,7 @@ static void pidfile_callback(void *arg, int fd, int events) */ static void pidfile_reconf(void *_null) { - static char cond[MAX_ARG_LEN]; + static char cond[MAX_COND_LEN]; svc_t *svc; (void)(_null); int restart = 0; diff --git a/src/svc.h b/src/svc.h index 791a6ee9..c055de37 100644 --- a/src/svc.h +++ b/src/svc.h @@ -68,6 +68,7 @@ typedef enum { #define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */ #define MAX_ARG_LEN 64 #define MAX_STR_LEN 64 +#define MAX_COND_LEN (MAX_ARG_LEN * 3) #define MAX_USER_LEN 16 #define MAX_NUM_FDS 64 /* Max number of I/O plugins */ #define MAX_NUM_SVC 64 /* Enough? */ @@ -94,7 +95,7 @@ typedef struct svc { int runlevels; int sighup; /* This service supports SIGHUP :) */ svc_block_t block; /* Reason that this service is currently stopped */ - char cond[MAX_ARG_LEN]; + char cond[MAX_COND_LEN]; /* Incremented for each restart by service monitor. */ const unsigned int restart_counter;