libct/system: use securejoin for /proc/$pid/stat

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai
2025-07-19 16:30:26 +10:00
parent f0f9a6ba7f
commit a1ea773c3b
+13 -3
View File
@@ -2,10 +2,12 @@ package system
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/opencontainers/runc/internal/pathrs"
) )
// State is the status of a process. // State is the status of a process.
@@ -66,8 +68,16 @@ type Stat_t struct {
} }
// Stat returns a Stat_t instance for the specified process. // Stat returns a Stat_t instance for the specified process.
func Stat(pid int) (stat Stat_t, err error) { func Stat(pid int) (Stat_t, error) {
bytes, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat")) var stat Stat_t
statFile, err := pathrs.ProcPidOpen(pid, "stat", os.O_RDONLY)
if err != nil {
return stat, err
}
defer statFile.Close()
bytes, err := io.ReadAll(statFile)
if err != nil { if err != nil {
return stat, err return stat, err
} }