From: Duan Zhang Date: Fri, 8 Sep 2017 15:04:24 +0000 (+0800) Subject: client:fix a bug in lseek X-Git-Tag: v13.0.1~743^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e12ba12cd870187e0640ea9dcb1696b0a2f006a4;p=ceph.git client:fix a bug in lseek If offset less than 0,the lseek may cause f->pos less than 0. So read or write may error. Signed-off-by: Duan Zhang --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 49a65d81b788..edbd11a8da3f 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8537,27 +8537,34 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence) { Inode *in = f->inode.get(); int r; + loff_t pos = -1; switch (whence) { case SEEK_SET: - f->pos = offset; + pos = offset; break; case SEEK_CUR: - f->pos += offset; + pos += offset; break; case SEEK_END: r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); if (r < 0) return r; - f->pos = in->size + offset; + pos = in->size + offset; break; default: ceph_abort(); } + if (pos < 0) { + return -EINVAL; + } else { + f->pos = pos; + } + ldout(cct, 3) << "_lseek(" << f << ", " << offset << ", " << whence << ") = " << f->pos << dendl; return f->pos; }