修复Linux插件隔离文件关闭顺序
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-29 19:15:43 +08:00
1 parent 9b5146bc57
commit f6c935a4d7
1 file changed
+16 -7
+16 -7
View File
@@ -145,20 +145,24 @@ func copyPluginFile(sourcePath, targetPath string, uid, gid int, mode os.FileMod
_ = os.Remove(targetPath)
return fmt.Errorf("copy plugin configuration: %w", err)
}
if err := target.Close(); err != nil {
_ = os.Remove(targetPath)
return fmt.Errorf("close sandbox plugin configuration: %w", err)
}
if written > maxPluginConfigBytes {
_ = os.Remove(targetPath)
return errors.New("plugin configuration exceeds the allowed size")
}
if err := target.Chmod(mode); err != nil {
_ = target.Close()
_ = os.Remove(targetPath)
return fmt.Errorf("secure sandbox plugin configuration: %w", err)
}
if err := target.Chown(uid, gid); err != nil {
_ = target.Close()
_ = os.Remove(targetPath)
return fmt.Errorf("assign sandbox plugin configuration identity: %w", err)
}
if err := target.Close(); err != nil {
_ = os.Remove(targetPath)
return fmt.Errorf("close sandbox plugin configuration: %w", err)
}
return nil
}
@@ -219,15 +223,20 @@ func copyPluginExecutable(sourcePath, targetPath string, uid, gid int) error {
_ = target.Close()
return fmt.Errorf("sync sandbox plugin executable: %w", err)
}
if err := target.Close(); err != nil {
return fmt.Errorf("close sandbox plugin executable: %w", err)
}
if err := target.Chmod(0700); err != nil {
_ = target.Close()
_ = os.Remove(targetPath)
return fmt.Errorf("secure sandbox plugin executable: %w", err)
}
if err := target.Chown(uid, gid); err != nil {
_ = target.Close()
_ = os.Remove(targetPath)
return fmt.Errorf("assign sandbox plugin identity: %w", err)
}
if err := target.Close(); err != nil {
_ = os.Remove(targetPath)
return fmt.Errorf("close sandbox plugin executable: %w", err)
}
return nil
}