rbd: trigger an error on invalid max snaps value

In file include from rbd.go:931
var cMaxSnaps C.int
ret := C.rbd_snap_list(image.image, nil, &cMaxSnaps)
cSnaps := make([]C.rbd_snap_info_t, cMaxSnaps)
It is necessary to determine whether cMaxSnaps is a large 0. Otherwise, the following code will panic
ret = C.rbd_snap_list(image.image,&cSnaps[0], &cMaxSnaps)

Signed-off-by: zxysilent <zxysilent@outlook.com>
This commit is contained in:
zxysilent 2024-03-31 14:14:27 +08:00 committed by mergify[bot]
parent cfae965d25
commit 2146f1af0c

View File

@ -936,7 +936,10 @@ func (image *Image) GetSnapshotNames() (snaps []SnapInfo, err error) {
var cMaxSnaps C.int
ret := C.rbd_snap_list(image.image, nil, &cMaxSnaps)
// bugfix index out of range(&cSnaps[0])
if cMaxSnaps < 1 {
return nil, rbdError(ret)
}
cSnaps := make([]C.rbd_snap_info_t, cMaxSnaps)
snaps = make([]SnapInfo, cMaxSnaps)