Don't panic for a negative offset, just fail the operation with EINVAL.

This commit is contained in:
mlelstv 2022-07-31 13:08:18 +00:00
parent 3418b37ee3
commit 6eb0866937
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysvbfs_vnops.c,v 1.68 2021/10/20 03:08:17 thorpej Exp $ */
/* $NetBSD: sysvbfs_vnops.c,v 1.69 2022/07/31 13:08:18 mlelstv Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.68 2021/10/20 03:08:17 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.69 2022/07/31 13:08:18 mlelstv Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -632,7 +632,9 @@ sysvbfs_readdir(void *v)
uio->uio_offset, uio->uio_resid);
KDASSERT(vp->v_type == VDIR);
KDASSERT(uio->uio_offset >= 0);
if (uio->uio_offset < 0)
return EINVAL;
dp = malloc(sizeof(struct dirent), M_BFS, M_WAITOK | M_ZERO);

View File

@ -1,4 +1,4 @@
/* $NetBSD: v7fs_vnops.c,v 1.37 2022/05/22 11:27:36 andvar Exp $ */
/* $NetBSD: v7fs_vnops.c,v 1.38 2022/07/31 13:08:19 mlelstv Exp $ */
/*-
* Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.37 2022/05/22 11:27:36 andvar Exp $");
__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.38 2022/07/31 13:08:19 mlelstv Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@ -996,9 +996,11 @@ v7fs_readdir(void *v)
DPRINTF("offset=%zu residue=%zu\n", uio->uio_offset, uio->uio_resid);
KDASSERT(vp->v_type == VDIR);
KDASSERT(uio->uio_offset >= 0);
KDASSERT(v7fs_inode_isdir(inode));
if (uio->uio_offset < 0)
return EINVAL;
struct v7fs_readdir_arg arg;
arg.start = uio->uio_offset / sizeof(*dp);
arg.end = arg.start + uio->uio_resid / sizeof(*dp);