]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: fix possible use-after-free
authorSage Weil <sage@inktank.com>
Thu, 9 May 2013 16:40:00 +0000 (09:40 -0700)
committerSage Weil <sage@inktank.com>
Thu, 9 May 2013 17:49:00 +0000 (10:49 -0700)
(of the pointer)

CID 966634 (#1 of 1): Use after free (USE_AFTER_FREE)
2. use_after_free: Using freed pointer "ictx".

Signed-off-by: Sage Weil <sage@inktank.com>
src/librbd/librbd.cc

index 9513e1e5f2c72fcc86cc4643cfca01b910dbd333..89bbe595752a900f3ea22ff080342ae2d2a9690f 100644 (file)
@@ -692,7 +692,8 @@ extern "C" int rbd_open(rados_ioctx_t p, const char *name, rbd_image_t *image,
   librbd::ImageCtx *ictx = new librbd::ImageCtx(name, "", snap_name, io_ctx,
                                                false);
   int r = librbd::open_image(ictx);
-  *image = (rbd_image_t)ictx;
+  if (r >= 0)
+    *image = (rbd_image_t)ictx;
   return r;
 }
 
@@ -704,7 +705,8 @@ extern "C" int rbd_open_read_only(rados_ioctx_t p, const char *name,
   librbd::ImageCtx *ictx = new librbd::ImageCtx(name, "", snap_name, io_ctx,
                                                true);
   int r = librbd::open_image(ictx);
-  *image = (rbd_image_t)ictx;
+  if (r >= 0)
+    *image = (rbd_image_t)ictx;
   return r;
 }