]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: Remote attr validation fixes and optimisations
authorDave Chinner <dchinner@redhat.com>
Fri, 7 Jun 2013 12:24:51 +0000 (22:24 +1000)
committerBen Myers <bpm@sgi.com>
Tue, 6 Aug 2013 21:23:53 +0000 (16:23 -0500)
- optimise the calcuation for the number of blocks in a remote xattr.
- check attribute length against MAX_XATTR_SIZE, not MAXPATHLEN
- whitespace fixes

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
libxfs/xfs_attr_remote.c

index fa112adbca1a35aac029d6cc97f56e4e6ae2181c..f0ca926ee558fe17f53afcc672778ef1940d81ef 100644 (file)
@@ -29,15 +29,9 @@ xfs_attr3_rmt_blocks(
        struct xfs_mount *mp,
        int             attrlen)
 {
-       int             fsblocks = 0;
-       int             len = attrlen;
-
-       do {
-               fsblocks++;
-               len -= XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
-       } while (len > 0);
-
-       return fsblocks;
+       int             buflen = XFS_ATTR3_RMT_BUF_SPACE(mp,
+                                                        mp->m_sb.sb_blocksize);
+       return (attrlen + buflen - 1) / buflen;
 }
 
 static bool
@@ -56,7 +50,7 @@ xfs_attr3_rmt_verify(
        if (bp->b_bn != be64_to_cpu(rmt->rm_blkno))
                return false;
        if (be32_to_cpu(rmt->rm_offset) +
-                               be32_to_cpu(rmt->rm_bytes) >= MAXPATHLEN)
+                               be32_to_cpu(rmt->rm_bytes) >= XATTR_SIZE_MAX)
                return false;
        if (rmt->rm_owner == 0)
                return false;
@@ -160,7 +154,6 @@ xfs_attr3_rmt_hdr_ok(
 
        /* ok */
        return true;
-
 }
 
 /*
@@ -344,7 +337,6 @@ xfs_attr_rmtval_set(
                 * spill for another block every 9 headers we require in this
                 * loop.
                 */
-
                if (crcs && blkcnt == 0) {
                        int total_len;
 
@@ -399,9 +391,8 @@ xfs_attr_rmtval_set(
 
                byte_cnt = BBTOB(bp->b_length);
                byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, byte_cnt);
-               if (valuelen < byte_cnt) {
+               if (valuelen < byte_cnt)
                        byte_cnt = valuelen;
-               }
 
                buf = bp->b_addr;
                buf += xfs_attr3_rmt_hdr_set(mp, dp->i_ino, offset,