]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client:fix a bug in lseek
authorDuan Zhang <zhangduan@inspur.com>
Fri, 8 Sep 2017 15:04:24 +0000 (23:04 +0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 14 Feb 2020 04:46:51 +0000 (20:46 -0800)
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 <zhangduan@inspur.com>
(cherry picked from commit e12ba12cd870187e0640ea9dcb1696b0a2f006a4)

Conflicts:
src/client/Client.cc

Backport of this commit included because
394720ca6b731e4698f1dbc7896d294363ecb466 depends on it.

src/client/Client.cc

index 35ea7100eae8388b52552a57a328c379e3ea4980..5fb2e8db3c73a18a7b0c42cf3f8b94720cf1872c 100644 (file)
@@ -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;
 }