mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
prepare_pstree: fixup reading kernel pid_max
Two fixes (reported by coverity) and a minor nitpick: 1. Fix checking error from open_proc(). 2. Fix buffer overflow. MAX_ULONG can be 20 characters long, so ret = read() can return 20 and buf[ret] = 0 will overrun the buf. Make a buf one character longer (an extra byte for \0) and pass sizeof(buf) - 1 to read to fix it. 3. Call close() right after read(). This is a fixup to commit e68bded. Reported by Coverity, CID 168505, 168504. Cc: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Kir Kolyshkin <kir@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
parent
c44683c13a
commit
cb58aa84d6
@ -887,17 +887,17 @@ int prepare_pstree(void)
|
||||
int ret;
|
||||
pid_t pid_max = 0, kpid_max = 0;
|
||||
int fd;
|
||||
char buf[20];
|
||||
char buf[21];
|
||||
|
||||
fd = open_proc(PROC_GEN, PID_MAX_PATH);
|
||||
if (fd != 1) {
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
if (fd >= 0) {
|
||||
ret = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if (ret > 0) {
|
||||
buf[ret] = 0;
|
||||
kpid_max = strtoul(buf, NULL, 10);
|
||||
pr_debug("kernel pid_max=%d\n", kpid_max);
|
||||
}
|
||||
close (fd);
|
||||
}
|
||||
|
||||
ret = read_pstree_image(&pid_max);
|
||||
|
Loading…
x
Reference in New Issue
Block a user