From f95ecf95ba9695105895ae8abbce02a95d0f3b7e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 17 Apr 2021 19:43:55 +0200 Subject: [PATCH] spa: don't overrun the input array Read one byte less than the size of the buffer so that we still have room in the buffer to append the 0 byte. --- spa/plugins/support/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spa/plugins/support/cpu.c b/spa/plugins/support/cpu.c index 11b16e8f1..30273c9d0 100644 --- a/spa/plugins/support/cpu.c +++ b/spa/plugins/support/cpu.c @@ -63,11 +63,11 @@ static char *read_file(const char *name, char *buffer, size_t len) if ((fd = open(name, O_RDONLY | O_CLOEXEC, 0)) < 0) return NULL; - if ((n = read(fd, buffer, len)) < 0) { + if ((n = read(fd, buffer, len-1)) < 0) { close(fd); return NULL; } - buffer[n] = 0; + buffer[n] = '\0'; close(fd); return buffer; }