From: Sage Weil Date: Thu, 9 May 2013 16:40:00 +0000 (-0700) Subject: librbd: fix possible use-after-free X-Git-Tag: v0.63~49^2^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2bc088307220d2ed0858009e189ebdae3364ddeb;p=ceph.git librbd: fix possible use-after-free (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 --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 9513e1e5f2c7..89bbe595752a 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -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; }