From: Yu Watanabe Date: Mon, 13 Dec 2021 23:21:58 +0000 (+0900) Subject: udev: warn about truncation of program result X-Git-Tag: v251-rc1~647^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7056adbf16849316681106e77f57b95242d6759e;p=thirdparty%2Fsystemd.git udev: warn about truncation of program result Closes #21078. --- diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 3cb83023255..eb576508dea 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: