]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/FileJournal.cc: fix potential use after close cases
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 13 Nov 2014 19:14:32 +0000 (20:14 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 13 Nov 2014 22:39:10 +0000 (23:39 +0100)
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 <danny.al-gaaf@bisect.de>
src/os/FileJournal.cc

index 8b1fc7253bcc71656ba0c64c2336404deea24494..5cebfeb4183594838f2099377665bd13c692404c 100644 (file)
@@ -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;