]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fix rbd_open_by_id, rbd_open_by_id_read_only 33315/head
authoryangjun <yangjun@cmss.chinamobile.com>
Sun, 8 Dec 2019 01:09:53 +0000 (09:09 +0800)
committerNathan Cutler <ncutler@suse.com>
Fri, 14 Feb 2020 11:06:51 +0000 (12:06 +0100)
These methods incorrectly delete ImageCtx on error, resulting
in double-free heap corruption.

Fixes: https://tracker.ceph.com/issues/43178
Signed-off-by: yangjun <yangjun@cmss.chinamobile.com>
(cherry picked from commit 3457192c24a66ba499a7c9b1747bc29c79b34636)

Conflicts:
src/librbd/librbd.cc

src/librbd/librbd.cc

index de4ed31c560554c965801e83ca0577bda0aae9db..0e65fbc0302bb3369f783b41ee35c56eb4a40a42 100644 (file)
@@ -2911,9 +2911,7 @@ extern "C" int rbd_open_by_id(rados_ioctx_t p, const char *id,
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
   int r = ictx->state->open(false);
-  if (r < 0) {
-    delete ictx;
-  } else {
+  if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
   tracepoint(librbd, open_image_exit, r);
@@ -2984,9 +2982,7 @@ extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p, const char *id,
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
   int r = ictx->state->open(false);
-  if (r < 0) {
-    delete ictx;
-  } else {
+  if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
   tracepoint(librbd, open_image_exit, r);