Skip to content

Commit

Permalink
lxd/instance/drivers: Check for unknown fields in migration header
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Bolton <mark.bolton@canonical.com>
  • Loading branch information
boltmark committed Aug 22, 2024
1 parent 78622ac commit 14fd875
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6579,6 +6579,21 @@ func (d *qemu) MigrateSend(args instance.MigrateSendArgs) error {
return fmt.Errorf("Failed receiving migration offer response: %w", err)
}

// If we have unknown fields in the protobuf message, then we received
// unexpected data. This will only happen if we were sent a migration.MigrationControl
// instead of the expected migration.MigrationHeader. This implies that we have failed on
// the target before we were able to send the response header.
reflect := offerHeader.ProtoReflect()
unknownFields := reflect.GetUnknown()
if len(unknownFields) > 0 {
msg, err := shared.GetFirstUnknownField(unknownFields)
if err != nil {
return fmt.Errorf("Failed receiving migration offer response")
}

return fmt.Errorf(msg)
}

d.logger.Debug("Got migration offer response from target")

// Negotiated migration types.
Expand Down Expand Up @@ -7105,6 +7120,21 @@ func (d *qemu) MigrateReceive(args instance.MigrateReceiveArgs) error {
return fmt.Errorf("Failed receiving migration offer from source: %w", err)
}

// If we have unknown fields in the protobuf message, then we received
// unexpected data. This will only happen if we were sent a migration.MigrationControl
// instead of the expected migration.MigrationHeader. This implies that we have failed on
// the source before we were able to send the header.
reflect := offerHeader.ProtoReflect()
unknownFields := reflect.GetUnknown()
if len(unknownFields) > 0 {
msg, err := shared.GetFirstUnknownField(unknownFields)
if err != nil {
return fmt.Errorf("Failed receiving migration offer from source")
}

return fmt.Errorf(msg)
}

// When doing a cluster same-name move we cannot load the storage pool using the instance's volume DB
// record because it may be associated to the wrong cluster member. Instead we ascertain the pool to load
// using the instance's root disk device.
Expand Down

0 comments on commit 14fd875

Please sign in to comment.