]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: fix potential access violation 9583/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 8 Jun 2016 06:30:30 +0000 (14:30 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Wed, 8 Jun 2016 06:37:23 +0000 (14:37 +0800)
The _read() call may fail and return a negative result,
and thus when it is passed to "resid", which is of type of
"unsigned", overflow happens due to a forced cast that is
implicitly performed.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/client/Client.cc

index 31cc936bce8dc43d0e2cf3d5756b00db7af4cf61..98041d2b130aa86cd9f17d5c122299d88650622b 100644 (file)
@@ -8273,6 +8273,9 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, in
         bufferlist bl;
         int r = _read(fh, offset, totallen, &bl);
         ldout(cct, 3) << "preadv(" << fd << ", " <<  offset << ") = " << r << dendl;
+        if (r <= 0)
+          return r;
+
         int bufoff = 0;
         for (unsigned j = 0, resid = r; j < iovcnt && resid > 0; j++) {
                /*