From: Danny Al-Gaaf Date: Thu, 13 Nov 2014 19:14:32 +0000 (+0100) Subject: os/FileJournal.cc: fix potential use after close cases X-Git-Tag: v0.90~25^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=156d17c1bdab72dfe8ca4a14463a153e40776d93;p=ceph.git os/FileJournal.cc: fix potential use after close cases Fix checks after _open() calls to make sure to use the filehandle only if open returns '0'. Fix for: CID 1128395 (#1 of 1): Use after close (USE_AFTER_FREE) pass_closed_arg: Passing closed handle this->fd as an argument to pwrite. CID 1128396 (#1 of 2): Use after close (USE_AFTER_FREE) pass_closed_arg: Passing closed handle this->fd as an argument to read_header. CID 1128397 (#1 of 1): Use after close (USE_AFTER_FREE) pass_closed_arg: Passing closed handle this->fd as an argument to read_header. CID 1128398 (#1 of 1): Use after close (USE_AFTER_FREE) pass_closed_arg: Passing closed handle this->fd as an argument to read_header. CID 1128400 (#1 of 1): Use after close (USE_AFTER_FREE) pass_closed_arg: Passing closed handle this->fd as an argument to read_header. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 8b1fc7253bcc..5cebfeb41835 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -325,7 +325,7 @@ int FileJournal::check() int ret; ret = _open(false, false); - if (ret < 0) + if (ret) goto done; ret = read_header(); @@ -358,7 +358,7 @@ int FileJournal::create() dout(2) << "create " << fn << " fsid " << fsid << dendl; ret = _open(true, true); - if (ret < 0) + if (ret) goto done; // write empty header @@ -435,7 +435,7 @@ done: int FileJournal::peek_fsid(uuid_d& fsid) { int r = _open(false, false); - if (r < 0) + if (r) return r; r = read_header(); if (r < 0) @@ -451,7 +451,7 @@ int FileJournal::open(uint64_t fs_op_seq) uint64_t next_seq = fs_op_seq + 1; int err = _open(false); - if (err < 0) + if (err) return err; // assume writeable, unless... @@ -561,10 +561,14 @@ void FileJournal::close() int FileJournal::dump(ostream& out) { + int err = 0; + dout(10) << "dump" << dendl; - _open(false, false); + err = _open(false, false); + if (err) + return err; - int err = read_header(); + err = read_header(); if (err < 0) return err;