]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: warn about truncation of program result
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 13 Dec 2021 23:21:58 +0000 (08:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 Dec 2021 06:13:19 +0000 (15:13 +0900)
Closes #21078.

src/udev/udev-event.c

index 3cb830232554a6c5342f7a63f03b48d28f375994..eb576508dead8f34d92b3cb04c7944bdc55054b3 100644 (file)
@@ -569,6 +569,7 @@ int udev_check_format(const char *value, size_t *offset, const char **hint) {
 static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         Spawn *spawn = userdata;
         char buf[4096], *p;
+        bool full = false;
         size_t size;
         ssize_t l;
         int r;
@@ -585,7 +586,7 @@ static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userd
                 size = sizeof(buf);
         }
 
-        l = read(fd, p, size - 1);
+        l = read(fd, p, size - (p == buf));
         if (l < 0) {
                 if (errno == EAGAIN)
                         goto reenable;
@@ -596,6 +597,13 @@ static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userd
                 return 0;
         }
 
+        if ((size_t) l == size) {
+                log_device_warning(spawn->device, "Truncating stdout of '%s' up to %zu byte.",
+                                   spawn->cmd, spawn->result_size);
+                l--;
+                full = true;
+        }
+
         p[l] = '\0';
         if (fd == spawn->fd_stdout && spawn->result)
                 spawn->result_len += l;
@@ -616,7 +624,7 @@ static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userd
                                          fd == spawn->fd_stdout ? "out" : "err", *q);
         }
 
-        if (l == 0)
+        if (l == 0 || full)
                 return 0;
 
 reenable: