mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 14:25:52 +00:00
parser: fix /proc version file read
The parser was not checking for an error when reading from /proc/sys/kernel/osrelease. Additionally, valgrind was complaining because of the uninitialized space in the buffer in between where the read(2) had deposited its data and where the parser was writing a trailing NUL to close the string. This patch fixes the above by writing the NUL byte at the position at the end of the read characters and checks for a negative result from the read() call. Signed-off-by: Steve Beattie <steve@nxnw.org> Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
@@ -313,11 +313,11 @@ static size_t kernel_af_max(void) {
|
||||
if (!fd)
|
||||
/* fall back to default provided during build */
|
||||
return 0;
|
||||
res = read(fd, &buffer, sizeof(buffer));
|
||||
res = read(fd, &buffer, sizeof(buffer) - 1);
|
||||
close(fd);
|
||||
if (!res)
|
||||
if (res <= 0)
|
||||
return 0;
|
||||
buffer[sizeof(buffer)-1] = '\0';
|
||||
buffer[res] = '\0';
|
||||
res = sscanf(buffer, "2.6.%d", &major);
|
||||
if (res != 1)
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user