From: runsisi Date: Wed, 17 May 2017 12:46:43 +0000 (+0800) Subject: pybind/rbd: fix crash if more than 1024 images in trash bin X-Git-Tag: v12.1.0~10^2~81^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F15134%2Fhead;p=ceph.git pybind/rbd: fix crash if more than 1024 images in trash bin Signed-off-by: runsisi --- diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 772085c1ee92..cb03878141d8 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -2854,8 +2854,8 @@ cdef class SnapIterator(object): self.num_snaps = 10 while True: self.snaps = realloc_chk(self.snaps, - self.num_snaps * - sizeof(rbd_snap_info_t)) + self.num_snaps * + sizeof(rbd_snap_info_t)) with nogil: ret = rbd_snap_list(image.image, self.snaps, &self.num_snaps) if ret >= 0: @@ -2905,12 +2905,18 @@ cdef class TrashIterator(object): def __init__(self, ioctx): self.ioctx = convert_ioctx(ioctx) self.num_entries = 1024 - self.entries = realloc_chk(NULL, - sizeof(rbd_trash_image_info_t) * self.num_entries) - with nogil: - ret = rbd_trash_list(self.ioctx, self.entries, &self.num_entries) - if ret < 0: - raise make_ex(ret, 'error listing trash entries') + self.entries = NULL + while True: + self.entries = realloc_chk(self.entries, + self.num_entries * + sizeof(rbd_trash_image_info_t)) + with nogil: + ret = rbd_trash_list(self.ioctx, self.entries, &self.num_entries) + if ret >= 0: + self.num_entries = ret + break + elif ret != -errno.ERANGE: + raise make_ex(ret, 'error listing trash entries') __source_string = ['USER', 'MIRRORING']