Skip to content

Commit

Permalink
rbd: trigger an error on invalid max snaps value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zxysilent authored and mergify[bot] committed Apr 5, 2024
1 parent cfae965 commit 2146f1a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rbd/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2146f1a

Please sign in to comment.