From b8571bcc05cc81448b8d52ef8eef71f2eaefa987 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Tue, 18 Oct 2011 21:28:38 -0400 Subject: [PATCH] Minor PID string length fix Changed PID string length to 7 to accomodate an ending newline and NULL char when writing to the fwknopd .pid file. Without this fix, with a 5 digit PID the trailing newline would be truncated (no room for the ending NULL char). --- server/fwknopd.c | 13 ++++++++----- server/fwknopd.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/fwknopd.c b/server/fwknopd.c index 5783d760..340a9dbb 100644 --- a/server/fwknopd.c +++ b/server/fwknopd.c @@ -590,7 +590,7 @@ write_pid_file(fko_srv_options_t *opts) { pid_t old_pid, my_pid; int op_fd, lck_res, num_bytes; - char buf[6] = {0}; + char buf[PID_BUFLEN] = {0}; /* Reset errno (just in case) */ @@ -640,7 +640,7 @@ write_pid_file(fko_srv_options_t *opts) /* Write our PID to the file */ my_pid = getpid(); - snprintf(buf, 6, "%i\n", my_pid); + snprintf(buf, PID_BUFLEN, "%i\n", my_pid); if(opts->verbose > 1) log_msg(LOG_INFO, "[+] Writing my PID (%i) to the lock file: %s\n", @@ -667,15 +667,18 @@ static pid_t get_running_pid(fko_srv_options_t *opts) { int op_fd; - char buf[6] = {0}; - pid_t rpid = 0; + char buf[PID_BUFLEN] = {0}; + pid_t rpid = 0; op_fd = open(opts->config[CONF_FWKNOP_PID_FILE], O_RDONLY); if(op_fd > 0) { - if (read(op_fd, buf, 6) > 0) + if (read(op_fd, buf, PID_BUFLEN) > 0) + { + buf[PID_BUFLEN-1] = '\0'; rpid = (pid_t)atoi(buf); + } close(op_fd); } diff --git a/server/fwknopd.h b/server/fwknopd.h index 89fa6c82..ddb97476 100644 --- a/server/fwknopd.h +++ b/server/fwknopd.h @@ -62,4 +62,6 @@ #define CRYPT_OP_ENCRYPT 1 #define CRYPT_OP_DECRYPT 2 +#define PID_BUFLEN 7 + #endif /* FWKNOPD_H */