Make sure we don't read too much

This commit is contained in:
Wim Taymans 2020-05-20 13:59:55 +02:00
parent 236ebeeb68
commit ce98162ed2
2 changed files with 5 additions and 3 deletions

View file

@ -53,6 +53,7 @@ struct impl {
static int check_cmdline(struct pw_impl_client *client, int pid, const char *str) static int check_cmdline(struct pw_impl_client *client, int pid, const char *str)
{ {
char path[2048]; char path[2048];
ssize_t len;
int fd; int fd;
sprintf(path, "/proc/%u/cmdline", pid); 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) if (fd < 0)
return -errno; return -errno;
if (read(fd, path, 1024) <= 0) { if ((len = read(fd, path, sizeof(path)-1)) < 0) {
close(fd); close(fd);
return -EIO; return -errno;
} }
path[len] = '\0';
if (strcmp(path, str) == 0) { if (strcmp(path, str) == 0) {
close(fd); close(fd);

View file

@ -2708,7 +2708,7 @@ static void do_input(void *data, int fd, uint32_t mask)
if (mask & SPA_IO_IN) { if (mask & SPA_IO_IN) {
while (true) { while (true) {
r = read(fd, buf, sizeof(buf)); r = read(fd, buf, sizeof(buf)-1);
if (r < 0) { if (r < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
continue; continue;