diff options
author | Joern Engel <joern@logfs.org> | 2012-01-16 12:53:47 -0800 |
---|---|---|
committer | Joern Engel <joern@logfs.org> | 2012-01-16 12:53:47 -0800 |
commit | 7f9450c5281fb0e0ba27e92dcc99bf1475b13715 (patch) | |
tree | de87ca7f8aa7d84ce319f017bf0495e21bd72454 | |
parent | e0bbe42647f27da852cf629eb2ad7d0bd8d3055f (diff) | |
download | cancd-7f9450c5281fb0e0ba27e92dcc99bf1475b13715.tar.gz |
Fix e0bbe426
Last commit clearly was untested. Don't commit on an airport, ever.
- NUL-terminate string before handing it off to strchrnul().
- Fix off-by-one (NUL byte).
- Fix spelling.
Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r-- | cancd.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -297,7 +297,7 @@ static int do_write(int fd, const void *buf, size_t count) return 0; } -static int write_formated(int fd, char *buf, size_t count) +static int write_formatted(int fd, char *buf, int count) { const char *format = "%b %d %H:%M:%S "; char *end; @@ -306,6 +306,7 @@ static int write_formated(int fd, char *buf, size_t count) time_t now = time(NULL); struct tm *tm = localtime(&now); + count += 1; /* add terminating NUL */ while (count) { end = strchrnul(buf, 0xa); *end = 0xa; @@ -349,7 +350,7 @@ static void do_output(char *buf, int len, struct sockaddr_in *addr, socklen_t so if (fd < 0) syslog(LOG_ERR, "Unable to open \"%s\": %s", name, strerror(errno)); else { - write_formated(fd, buf, len); + write_formatted(fd, buf, len); close(fd); } free(name); @@ -442,6 +443,7 @@ static int run() syslog(LOG_ERR, "Error reading from socket: %s", strerror(-rc)); break; } + buf[rc] = 0; /* For now, we process one at a time */ do_output(buf, rc, &from, fromlen); } |