Commit ec863205 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Pavel Emelyanov

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: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 377763e5
...@@ -45,8 +45,8 @@ int read_ns_sys_file(char *path, char *buf, int len) ...@@ -45,8 +45,8 @@ int read_ns_sys_file(char *path, char *buf, int len)
rlen = read(fd, buf, len); rlen = read(fd, buf, len);
close(fd); close(fd);
if (rlen >= 0) if (rlen > 0)
buf[rlen] = '\0'; buf[rlen - 1] = '\0';
return rlen; return rlen;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment