chiark / gitweb /
journald: fix some xsprrintf() buffer size fallout
[elogind.git] / src / journal / journald-kmsg.c
index 363c5de86938de6cbb4ebe760905f31524aec319..c4216c4043370bb8047c99a07faf9336cc9bfe16 100644 (file)
@@ -40,7 +40,8 @@ void server_forward_kmsg(
         const struct ucred *ucred) {
 
         struct iovec iovec[5];
-        char header_priority[6], header_pid[16];
+        char header_priority[DECIMAL_STR_MAX(priority) + 3],
+             header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t) + 1];
         int n = 0;
         char *ident_buf = NULL;
 
@@ -60,8 +61,7 @@ void server_forward_kmsg(
         priority = syslog_fixup_facility(priority);
 
         /* First: priority field */
-        snprintf(header_priority, sizeof(header_priority), "<%i>", priority);
-        char_array_0(header_priority);
+        xsprintf(header_priority, "<%i>", priority);
         IOVEC_SET_STRING(iovec[n++], header_priority);
 
         /* Second: identifier and PID */
@@ -71,8 +71,7 @@ void server_forward_kmsg(
                         identifier = ident_buf;
                 }
 
-                snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", ucred->pid);
-                char_array_0(header_pid);
+                xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
 
                 if (identifier)
                         IOVEC_SET_STRING(iovec[n++], identifier);
@@ -88,7 +87,7 @@ void server_forward_kmsg(
         IOVEC_SET_STRING(iovec[n++], "\n");
 
         if (writev(s->dev_kmsg_fd, iovec, n) < 0)
-                log_debug("Failed to write to /dev/kmsg for logging: %m");
+                log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m");
 
         free(ident_buf);
 }
@@ -342,7 +341,7 @@ static int server_read_dev_kmsg(Server *s) {
                 if (errno == EAGAIN || errno == EINTR || errno == EPIPE)
                         return 0;
 
-                log_error("Failed to read from kernel: %m");
+                log_error_errno(errno, "Failed to read from kernel: %m");
                 return -errno;
         }
 
@@ -446,18 +445,18 @@ int server_open_kernel_seqnum(Server *s) {
 
         fd = open("/run/systemd/journal/kernel-seqnum", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
         if (fd < 0) {
-                log_error("Failed to open /run/systemd/journal/kernel-seqnum, ignoring: %m");
+                log_error_errno(errno, "Failed to open /run/systemd/journal/kernel-seqnum, ignoring: %m");
                 return 0;
         }
 
         if (posix_fallocate(fd, 0, sizeof(uint64_t)) < 0) {
-                log_error("Failed to allocate sequential number file, ignoring: %m");
+                log_error_errno(errno, "Failed to allocate sequential number file, ignoring: %m");
                 return 0;
         }
 
         p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
         if (p == MAP_FAILED) {
-                log_error("Failed to map sequential number file, ignoring: %m");
+                log_error_errno(errno, "Failed to map sequential number file, ignoring: %m");
                 return 0;
         }