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.
This commit is contained in:
Wim Taymans 2021-04-17 19:43:55 +02:00
parent d2d01b43d3
commit f95ecf95ba

View file

@ -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;
}