From: Duan Zhang Date: Fri, 8 Sep 2017 15:04:24 +0000 (+0800) Subject: client:fix a bug in lseek X-Git-Tag: v12.2.14~11^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=92c4163ad6e6e150fa10e2f1dd3d2f17cf5a400f;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 (cherry picked from commit e12ba12cd870187e0640ea9dcb1696b0a2f006a4) Conflicts: src/client/Client.cc Backport of this commit included because 394720ca6b731e4698f1dbc7896d294363ecb466 depends on it. --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 35ea7100eae8..5fb2e8db3c73 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8729,28 +8729,35 @@ 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(); } - ldout(cct, 8) << "_lseek(" << f << ", " << offset << ", " << whence << ") = " << f->pos << dendl; + if (pos < 0) { + return -EINVAL; + } else { + f->pos = pos; + } + + ldout(cct, 3) << "_lseek(" << f << ", " << offset << ", " << whence << ") = " << f->pos << dendl; return f->pos; }