Skip to content

Commit 3b29970

Browse files
author
J. Bruce Fields
committed
nfsd4: enforce rd_dircount
As long as we're here, let's enforce the protocol's limit on the number of directory entries to return in a readdir. I don't think anyone's ever noticed our lack of enforcement, but maybe there's more of a chance they will now that we allow larger readdirs. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 561f0ed commit 3b29970

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎fs/nfsd/nfs4xdr.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *read
10331033
READ_BUF(24);
10341034
READ64(readdir->rd_cookie);
10351035
COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
1036-
READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
1036+
READ32(readdir->rd_dircount);
10371037
READ32(readdir->rd_maxcount);
10381038
if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
10391039
goto out;
@@ -2720,6 +2720,9 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
27202720
if (entry_bytes > cd->rd_maxcount)
27212721
goto fail;
27222722
cd->rd_maxcount -= entry_bytes;
2723+
if (!cd->rd_dircount)
2724+
goto fail;
2725+
cd->rd_dircount--;
27232726
cd->cookie_offset = cookie_offset;
27242727
skip_entry:
27252728
cd->common.err = nfs_ok;

0 commit comments

Comments
 (0)