]> err.no Git - util-linux/commitdiff
logger: use snprintf instead of sprintf in logger.c
authorLaMont Jones <lamont@mmjgroup.com>
Wed, 18 Jul 2007 04:43:15 +0000 (22:43 -0600)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2007 22:22:20 +0000 (00:22 +0200)
Signed-off-by: LaMont Jones <lamont@mmjgroup.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/logger.c

index 5241a1939083f21e1e619f447f3bd05cfc715594..9a7cb05881f92e523d7738b6ff461af366671be1 100644 (file)
@@ -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), "[%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), "<%d>%.15s %.200s%s: %.400s",
                        pri, tp, cp, pid, msg);
 
                if (write(fd, buf, strlen(buf)+1) < 0)