From dd2898f85e26d2b2a77f114dc034be495bf0ea7a Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Mon, 13 Apr 2026 15:04:57 +0800 Subject: [PATCH] fix: add bounds check for /proc/[pid]/stat fields to prevent panic fillFromTIDStatWithContext accesses fields up to index 22 without bounds checking. This causes an index-out-of-range panic when /proc/[pid]/stat has fewer than 23 fields, which can happen in container environments or with non-standard kernels. The function already guards fields[42] with a length check but is missing the same protection for lower-indexed fields. Fixes #2070 --- process/process_linux.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/process/process_linux.go b/process/process_linux.go index 764523d..0220ab2 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -1046,6 +1046,9 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui } // Indexing from one, as described in `man proc` about the file /proc/[pid]/stat fields := splitProcStat(contents) + if len(fields) < 23 { + return 0, 0, nil, 0, 0, 0, nil, fmt.Errorf("malformed stat file: expected at least 23 fields, got %d", len(fields)) + } terminal, err := strconv.ParseUint(fields[7], 10, 64) if err != nil { -- knotmirror 0.0.1