• Kir Kolyshkin's avatar
    prepare_pstree: fixup reading kernel pid_max · cb58aa84
    Kir Kolyshkin authored
    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: 's avatarKir Kolyshkin <kir@openvz.org>
    Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
    cb58aa84
pstree.c 22.1 KB