Skip to content

Commit d61fd29

Browse files
committed
libct/system: use securejoin for /proc/$pid/stat
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 435cc81 commit d61fd29

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

libcontainer/system/proc.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package system
22

33
import (
44
"fmt"
5+
"io"
56
"os"
6-
"path/filepath"
77
"strconv"
88
"strings"
9+
10+
"github.com/opencontainers/runc/internal/pathrs"
911
)
1012

1113
// State is the status of a process.
@@ -66,8 +68,16 @@ type Stat_t struct {
6668
}
6769

6870
// Stat returns a Stat_t instance for the specified process.
69-
func Stat(pid int) (stat Stat_t, err error) {
70-
bytes, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
71+
func Stat(pid int) (Stat_t, error) {
72+
var stat Stat_t
73+
74+
statFile, err := pathrs.ProcPidOpen(pid, "stat", os.O_RDONLY)
75+
if err != nil {
76+
return stat, err
77+
}
78+
defer statFile.Close()
79+
80+
bytes, err := io.ReadAll(statFile)
7181
if err != nil {
7282
return stat, err
7383
}

0 commit comments

Comments
 (0)