]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fix rbd_open_by_id, rbd_open_by_id_read_only 32105/head
authoryangjun <yangjun@cmss.chinamobile.com>
Sun, 8 Dec 2019 01:09:53 +0000 (09:09 +0800)
committerJason Dillaman <dillaman@redhat.com>
Mon, 9 Dec 2019 14:08:22 +0000 (09:08 -0500)
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>
src/librbd/librbd.cc

index 0b8db4ff8b7957d17c2e061f596c6dd3cc3dcab7..680b240643700de93ec388bbc96b64a2aa832aa9 100644 (file)
@@ -4434,9 +4434,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(0);
-  if (r < 0) {
-    delete ictx;
-  } else {
+  if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
   tracepoint(librbd, open_image_exit, r);
@@ -4509,9 +4507,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(0);
-  if (r < 0) {
-    delete ictx;
-  } else {
+  if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
   tracepoint(librbd, open_image_exit, r);