aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/nfs/nfs4xdr.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 37421dd4805d..2b519f6325f9 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -3481,7 +3481,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3481 size_t hdrlen; 3481 size_t hdrlen;
3482 u32 recvd, pglen = rcvbuf->page_len; 3482 u32 recvd, pglen = rcvbuf->page_len;
3483 __be32 *end, *entry, *p, *kaddr; 3483 __be32 *end, *entry, *p, *kaddr;
3484 unsigned int nr; 3484 unsigned int nr = 0;
3485 int status; 3485 int status;
3486 3486
3487 status = decode_op_hdr(xdr, OP_READDIR); 3487 status = decode_op_hdr(xdr, OP_READDIR);
@@ -3505,7 +3505,12 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3505 kaddr = p = kmap_atomic(page, KM_USER0); 3505 kaddr = p = kmap_atomic(page, KM_USER0);
3506 end = p + ((pglen + readdir->pgbase) >> 2); 3506 end = p + ((pglen + readdir->pgbase) >> 2);
3507 entry = p; 3507 entry = p;
3508 for (nr = 0; *p++; nr++) { 3508
3509 /* Make sure the packet actually has a value_follows and EOF entry */
3510 if ((entry + 1) > end)
3511 goto short_pkt;
3512
3513 for (; *p++; nr++) {
3509 u32 len, attrlen, xlen; 3514 u32 len, attrlen, xlen;
3510 if (end - p < 3) 3515 if (end - p < 3)
3511 goto short_pkt; 3516 goto short_pkt;
@@ -3532,20 +3537,32 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3532 p += attrlen; /* attributes */ 3537 p += attrlen; /* attributes */
3533 entry = p; 3538 entry = p;
3534 } 3539 }
3535 if (!nr && (entry[0] != 0 || entry[1] == 0)) 3540 /*
3536 goto short_pkt; 3541 * Apparently some server sends responses that are a valid size, but
3542 * contain no entries, and have value_follows==0 and EOF==0. For
3543 * those, just set the EOF marker.
3544 */
3545 if (!nr && entry[1] == 0) {
3546 dprintk("NFS: readdir reply truncated!\n");
3547 entry[1] = 1;
3548 }
3537out: 3549out:
3538 kunmap_atomic(kaddr, KM_USER0); 3550 kunmap_atomic(kaddr, KM_USER0);
3539 return 0; 3551 return 0;
3540short_pkt: 3552short_pkt:
3553 /*
3554 * When we get a short packet there are 2 possibilities. We can
3555 * return an error, or fix up the response to look like a valid
3556 * response and return what we have so far. If there are no
3557 * entries and the packet was short, then return -EIO. If there
3558 * are valid entries in the response, return them and pretend that
3559 * the call was successful, but incomplete. The caller can retry the
3560 * readdir starting at the last cookie.
3561 */
3541 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); 3562 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3542 entry[0] = entry[1] = 0; 3563 entry[0] = entry[1] = 0;
3543 /* truncate listing ? */ 3564 if (nr)
3544 if (!nr) { 3565 goto out;
3545 dprintk("NFS: readdir reply truncated!\n");
3546 entry[1] = 1;
3547 }
3548 goto out;
3549err_unmap: 3566err_unmap:
3550 kunmap_atomic(kaddr, KM_USER0); 3567 kunmap_atomic(kaddr, KM_USER0);
3551 return -errno_NFSERR_IO; 3568 return -errno_NFSERR_IO;