From ce98162ed24c6bc34a97b0ad2bb1d6404c98f97e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 20 May 2020 13:59:55 +0200 Subject: [PATCH] Make sure we don't read too much --- src/modules/module-access.c | 6 ++++-- src/tools/pw-cli.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/module-access.c b/src/modules/module-access.c index c31ce709e..ff35b7d07 100644 --- a/src/modules/module-access.c +++ b/src/modules/module-access.c @@ -53,6 +53,7 @@ struct impl { static int check_cmdline(struct pw_impl_client *client, int pid, const char *str) { char path[2048]; + ssize_t len; int fd; sprintf(path, "/proc/%u/cmdline", pid); @@ -61,10 +62,11 @@ static int check_cmdline(struct pw_impl_client *client, int pid, const char *str if (fd < 0) return -errno; - if (read(fd, path, 1024) <= 0) { + if ((len = read(fd, path, sizeof(path)-1)) < 0) { close(fd); - return -EIO; + return -errno; } + path[len] = '\0'; if (strcmp(path, str) == 0) { close(fd); diff --git a/src/tools/pw-cli.c b/src/tools/pw-cli.c index bb90a2e83..8f6e77c32 100644 --- a/src/tools/pw-cli.c +++ b/src/tools/pw-cli.c @@ -2708,7 +2708,7 @@ static void do_input(void *data, int fd, uint32_t mask) if (mask & SPA_IO_IN) { while (true) { - r = read(fd, buf, sizeof(buf)); + r = read(fd, buf, sizeof(buf)-1); if (r < 0) { if (errno == EAGAIN) continue;