mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
incusd/instance/qemu: Use os.Root for template output
Matches the LXC driver, the existing checks already prevent escaping. Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
8e2eab60d8
commit
154089f398
@ -3777,6 +3777,14 @@ func (d *qemu) templateApplyNow(trigger instance.TemplateTrigger, path string) e
|
||||
instanceMeta["ephemeral"] = "false"
|
||||
}
|
||||
|
||||
// Open the output directory as an os.Root so all template writes stay confined to it.
|
||||
outputRoot, err := os.OpenRoot(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to open template output path: %w", err)
|
||||
}
|
||||
|
||||
defer logger.WarnOnError(outputRoot.Close, "Failed to close template output path")
|
||||
|
||||
// Go through the templates.
|
||||
for tplPath, tpl := range metadata.Templates {
|
||||
err = func(tplPath string, tpl *api.ImageMetadataTemplate) error {
|
||||
@ -3813,7 +3821,7 @@ func (d *qemu) templateApplyNow(trigger instance.TemplateTrigger, path string) e
|
||||
}
|
||||
|
||||
// Create the file itself.
|
||||
w, err = os.Create(filepath.Join(path, fmt.Sprintf("%s.out", tpl.Template)))
|
||||
w, err = outputRoot.Create(fmt.Sprintf("%s.out", tpl.Template))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user