rbd: fixed all potential crashing when decoding volume ID failed

Signed-off-by: HF <crazytaxii666@gmail.com>
This commit is contained in:
HF 2023-09-06 05:06:06 -04:00 committed by mergify[bot]
parent 97df4e79c6
commit 5411a69839
2 changed files with 35 additions and 7 deletions

View File

@ -243,7 +243,11 @@ func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):
@ -305,7 +309,11 @@ func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):
@ -376,7 +384,11 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):
@ -472,7 +484,11 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):
@ -585,7 +601,11 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
} }
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):
@ -798,7 +818,11 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
} }
defer rs.VolumeLocks.Release(volumeID) defer rs.VolumeLocks.Release(volumeID)
rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets()) rbdVol, err := corerbd.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, corerbd.ErrImageNotFound): case errors.Is(err, corerbd.ErrImageNotFound):

View File

@ -1082,7 +1082,11 @@ func (cs *ControllerServer) CreateSnapshot(
// Fetch source volume information // Fetch source volume information
rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets()) rbdVol, err := GenVolFromVolID(ctx, req.GetSourceVolumeId(), cr, req.GetSecrets())
defer rbdVol.Destroy() defer func() {
if rbdVol != nil {
rbdVol.Destroy()
}
}()
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, ErrImageNotFound): case errors.Is(err, ErrImageNotFound):