From 999393949c1ee8225d1703156c39575b1ed99cbb Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Tue, 23 Apr 2013 15:57:48 +0200 Subject: [PATCH] Revert "Remove size check that required a costly fstat()" This reverts commit 2d4c0bd1e9b0ad0db32e4f3705fe67f657f57230. --- etc/afpd/fork.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index a77c6adc..0c988828 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -759,7 +759,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si { DSI *dsi = obj->dsi; struct ofork *ofork; - off_t offset, saveoff, reqcount, savereqcount; + off_t offset, saveoff, reqcount, savereqcount, size; ssize_t cc, err; int eid; uint16_t ofrefnum; @@ -801,9 +801,23 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si AFP_READ_START((long)reqcount); + /* reqcount isn't always truthful. we need to deal with that. */ + size = ad_size(ofork->of_ad, eid); + LOG(log_debug, logtype_afpd, - "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ")", - ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount); + "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ", size: %" PRIu64 ")", + ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount, size); + + if (offset >= size) { + err = AFPERR_EOF; + goto afp_read_err; + } + + /* subtract off the offset */ + if (reqcount + offset > size) { + reqcount = size - offset; + err = AFPERR_EOF; + } savereqcount = reqcount; saveoff = offset; -- 2.39.2