2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00

read_ns_sys_file(): don't overrun buf

This is a classical off-by-one error. If sizeof(buf) is 512,
the last element is buf[511] but not buf[512].

Note that if read() returns 0, we return 0 but buf stays
uninitialized.

Reported by Coverity, CID 114623.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Kir Kolyshkin
2015-10-07 02:44:18 -07:00
committed by Pavel Emelyanov
parent 377763e5b1
commit ec863205f4

4
net.c
View File

@@ -45,8 +45,8 @@ int read_ns_sys_file(char *path, char *buf, int len)
rlen = read(fd, buf, len);
close(fd);
if (rlen >= 0)
buf[rlen] = '\0';
if (rlen > 0)
buf[rlen - 1] = '\0';
return rlen;
}