From: 胡玮文 Date: Sat, 22 Nov 2025 03:00:47 +0000 (+0800) Subject: internal/runtime/cgroup: stricter unescapePath X-Git-Tag: go1.26rc1~44 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cead111a77;p=gostls13.git internal/runtime/cgroup: stricter unescapePath 8 and 9 in escape sequence is invalid now, it should be octal. Escape sequence larger than \377 is invalid now, it does not fit one byte. Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2 Reviewed-on: https://go-review.googlesource.com/c/go/+/723242 Reviewed-by: Dmitri Shuralyov Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Auto-Submit: Dmitri Shuralyov --- diff --git a/src/internal/runtime/cgroup/cgroup.go b/src/internal/runtime/cgroup/cgroup.go index 09519af1e1..46a25ad28b 100644 --- a/src/internal/runtime/cgroup/cgroup.go +++ b/src/internal/runtime/cgroup/cgroup.go @@ -474,18 +474,21 @@ func unescapePath(out []byte, in []byte) (int, error) { return outi, errInvalidEscape } - var outc byte + var outc int for i := range 3 { c := in[ini+1+i] - if c < '0' || c > '9' { + if c < '0' || c > '7' { return outi, errInvalidEscape } outc *= 8 - outc += c - '0' + outc += int(c - '0') } - out[outi] = outc + if outc > 0xFF { + return outi, errInvalidEscape + } + out[outi] = byte(outc) outi++ ini += 4 diff --git a/src/internal/runtime/cgroup/cgroup_test.go b/src/internal/runtime/cgroup/cgroup_test.go index 79263821c3..a82c7b3bf4 100644 --- a/src/internal/runtime/cgroup/cgroup_test.go +++ b/src/internal/runtime/cgroup/cgroup_test.go @@ -682,3 +682,23 @@ b/c`, } }) } + +func TestUnescapeInvalidPath(t *testing.T) { + for _, in := range []string{ + `/a/b\c`, + `/a/b\01`, + `/a/b\018`, + `/a/b\01c`, + `/a/b\777`, + `01234567890123456789`, // too long + `\001\002\003\004\005\006\007\010\011`, // too long + } { + out := make([]byte, 8) + t.Run(in, func(t *testing.T) { + _, err := cgroup.UnescapePath(out, []byte(in)) + if err == nil { + t.Errorf("unescapePath got nil err, want non-nil") + } + }) + } +}