Skip to content

Commit f408405

Browse files
zxysilentphlogistonjohn
authored andcommitted
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>
1 parent cfae965 commit f408405

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rbd/rbd.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,10 @@ func (image *Image) GetSnapshotNames() (snaps []SnapInfo, err error) {
936936
var cMaxSnaps C.int
937937

938938
ret := C.rbd_snap_list(image.image, nil, &cMaxSnaps)
939-
939+
// bugfix index out of range(&cSnaps[0])
940+
if cMaxSnaps < 1 {
941+
return nil, rbdError(ret)
942+
}
940943
cSnaps := make([]C.rbd_snap_info_t, cMaxSnaps)
941944
snaps = make([]SnapInfo, cMaxSnaps)
942945

0 commit comments

Comments
 (0)