From: LaMont Jones Date: Wed, 18 Jul 2007 04:43:15 +0000 (-0600) Subject: use snprintf instead of sprintf in logger.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fa72900a4a5ee48214e6aaab92c1ad797ef2145;p=util-linux use snprintf instead of sprintf in logger.c --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 5241a193..ae23e347 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -89,9 +89,8 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) { time_t now; if (fd > -1) { - /* avoid snprintf - it does not exist on ancient systems */ if (logflags & LOG_PID) - sprintf (pid, "[%d]", getpid()); + snprintf (pid, sizeof(pid)-1, "[%d]", getpid()); else pid[0] = 0; if (tag) @@ -104,8 +103,7 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) { (void)time(&now); tp = ctime(&now)+4; - /* do snprintf by hand - ugly, but for once... */ - sprintf(buf, "<%d>%.15s %.200s%s: %.400s", + snprintf(buf, sizeof(buf)-1, "<%d>%.15s %.200s%s: %.400s", pri, tp, cp, pid, msg); if (write(fd, buf, strlen(buf)+1) < 0)