From 3fc893bc0f4611d926e720d2ee7762dc7a493251 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 10 Jun 2020 10:38:56 +0200 Subject: [PATCH] rbd: add error checking in RemoveImage() Signed-off-by: Niels de Vos --- rbd/rbd.go | 7 +++++++ rbd/rbd_test.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/rbd/rbd.go b/rbd/rbd.go index 61f9669..7863688 100644 --- a/rbd/rbd.go +++ b/rbd/rbd.go @@ -1216,6 +1216,13 @@ func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *ImageOpt // Implements: // int rbd_remove(rados_ioctx_t io, const char *name); func RemoveImage(ioctx *rados.IOContext, name string) error { + if ioctx == nil { + return ErrNoIOContext + } + if name == "" { + return ErrNoName + } + c_name := C.CString(name) defer C.free(unsafe.Pointer(c_name)) return getError(C.rbd_remove(cephIoctx(ioctx), c_name)) diff --git a/rbd/rbd_test.go b/rbd/rbd_test.go index f34d752..39800de 100644 --- a/rbd/rbd_test.go +++ b/rbd/rbd_test.go @@ -1300,6 +1300,12 @@ func TestRemoveImage(t *testing.T) { ioctx, err := conn.OpenIOContext(poolname) require.NoError(t, err) + // pass invalid parameters + err = RemoveImage(nil, "some-name") + require.Error(t, err) + err = RemoveImage(ioctx, "") + require.Error(t, err) + // trying to remove a non-existent image is an error err = RemoveImage(ioctx, "bananarama") require.Error(t, err)