]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime/cgroup: stricter unescapePath
author胡玮文 <huweiwen.hww@alibaba-inc.com>
Sat, 22 Nov 2025 03:00:47 +0000 (11:00 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 27 Nov 2025 06:29:49 +0000 (22:29 -0800)
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 <dmitshur@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>

src/internal/runtime/cgroup/cgroup.go
src/internal/runtime/cgroup/cgroup_test.go

index 09519af1e10d8ddaccecbca151890b34f74e08a0..46a25ad28b3b6110bcb83dd7a5353b8f4791b512 100644 (file)
@@ -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
index 79263821c3c5b4b60cf3eb7227df4729be33551c..a82c7b3bf4edb9110ada9d9532f293b1b2803237 100644 (file)
@@ -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")
+                       }
+               })
+       }
+}