diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-14 08:21:58 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-25 15:13:19 +0900 |
commit | 7056adbf16849316681106e77f57b95242d6759e (patch) | |
tree | f5bc254822ea74e87533f9d864415299c3444ced /src | |
parent | f6caab8995a27244db185f075e751a119e4bdedc (diff) | |
download | systemd-7056adbf16849316681106e77f57b95242d6759e.tar.gz |
udev: warn about truncation of program result
Closes #21078.
Diffstat (limited to 'src')
-rw-r--r-- | src/udev/udev-event.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 3cb8302325..eb576508de 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -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: |