]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client:fix a bug in lseek 17604/head
authorDuan Zhang <zhangduan@inspur.com>
Fri, 8 Sep 2017 15:04:24 +0000 (23:04 +0800)
committerDuan Zhang <zhangduan@inspur.com>
Thu, 21 Sep 2017 05:46:55 +0000 (13: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>
src/client/Client.cc

index 49a65d81b788ddbac749708857a28d18928870d9..edbd11a8da3febc9153c8cefb2e9a1ef5d026d2e 100644 (file)
@@ -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;
 }