xfs
[Top] [All Lists]

[PATCH 9/9] xfs: check for valid indices in xfs_iext_get_ext and xfs_iex

To: xfs@xxxxxxxxxxx
Subject: [PATCH 9/9] xfs: check for valid indices in xfs_iext_get_ext and xfs_iext_idx_to_irec
From: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Date: Wed, 11 May 2011 11:04:11 -0400
References: <20110511150402.258164661@xxxxxxxxxxxxxxxxxxxxxx>
User-agent: quilt/0.48-1
Based on an earlier patch from Lachlan McIlroy.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>

Index: xfs/fs/xfs/xfs_inode.c
===================================================================
--- xfs.orig/fs/xfs/xfs_inode.c 2011-05-11 12:05:12.943735034 +0200
+++ xfs/fs/xfs/xfs_inode.c      2011-05-11 12:05:28.327733646 +0200
@@ -3108,6 +3108,8 @@ xfs_iext_get_ext(
        xfs_extnum_t    idx)            /* index of target extent */
 {
        ASSERT(idx >= 0);
+       ASSERT(idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t));
+
        if ((ifp->if_flags & XFS_IFEXTIREC) && (idx == 0)) {
                return ifp->if_u1.if_ext_irec->er_extbuf;
        } else if (ifp->if_flags & XFS_IFEXTIREC) {
@@ -3881,8 +3883,10 @@ xfs_iext_idx_to_irec(
        xfs_extnum_t    page_idx = *idxp; /* extent index in target list */
 
        ASSERT(ifp->if_flags & XFS_IFEXTIREC);
-       ASSERT(page_idx >= 0 && page_idx <=
-               ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t));
+       ASSERT(page_idx >= 0);
+       ASSERT(page_idx <= ifp->if_bytes / sizeof(xfs_bmbt_rec_t));
+       ASSERT(page_idx < ifp->if_bytes / sizeof(xfs_bmbt_rec_t) || realloc);
+
        nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
        erp_idx = 0;
        low = 0;

<Prev in Thread] Current Thread [Next in Thread>