From 2ca8db71364698e05c3a6ac9a5aa4da5421a35bc Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 6 Feb 2020 12:00:07 -0500 Subject: [PATCH] client: fix error handling in lseek SEEK_HOLE/SEEK_DATA cases The error handling here looks quite wrong. If the offset represents an area outside the file, then we want to just return -ENXIO immediately. Fixes: https://tracker.ceph.com/issues/44021 Signed-off-by: Jeff Layton --- src/client/Client.cc | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 737bfabe67f..b55973a0322 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8907,7 +8907,6 @@ loff_t Client::lseek(int fd, loff_t offset, int whence) loff_t Client::_lseek(Fh *f, loff_t offset, int whence) { Inode *in = f->inode.get(); - int r; bool whence_check = false; loff_t pos = -1; @@ -8930,10 +8929,9 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence) } if (whence_check) { - r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); - if (r < 0) { + int r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); + if (r < 0) return r; - } } switch (whence) { @@ -8951,22 +8949,17 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence) #ifdef SEEK_DATA case SEEK_DATA: - if (offset < 0 || static_cast(offset) >= in->size) { - r = -ENXIO; - return offset; - } + if (offset < 0 || static_cast(offset) >= in->size) + return -ENXIO; pos = offset; break; #endif #ifdef SEEK_HOLE case SEEK_HOLE: - if (offset < 0 || static_cast(offset) >= in->size) { - r = -ENXIO; - pos = offset; - } else { - pos = in->size; - } + if (offset < 0 || static_cast(offset) >= in->size) + return -ENXIO; + pos = in->size; break; #endif -- 2.39.5