Skip to content

Commit

Permalink
lxd-migrate: Prevent tarball as instance source
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <[email protected]>
  • Loading branch information
MusicDin committed Aug 5, 2024
1 parent 7ed80c1 commit 5befe3d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lxd-migrate/main_migrate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"archive/tar"
"bufio"
"context"
"errors"
Expand Down Expand Up @@ -357,11 +358,19 @@ func (c *cmdMigrate) runInteractive(server lxd.InstanceServer) (cmdMigrateData,
}
}

_, err := os.Stat(s)
file, err := os.Open(s)
if err != nil {
return err
}

defer file.Close()

// Ensure the source file is not a tarball.
_, err = tar.NewReader(file).Next()
if err == nil {
return fmt.Errorf("Source cannot be a tar archive or OVA file")
}

return nil
})
if err != nil {
Expand Down

0 comments on commit 5befe3d

Please sign in to comment.