Skip to content

Commit cead111

Browse files
huww98gopherbot
authored andcommitted
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 <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>
1 parent c2af9f1 commit cead111

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/internal/runtime/cgroup/cgroup.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,21 @@ func unescapePath(out []byte, in []byte) (int, error) {
474474
return outi, errInvalidEscape
475475
}
476476

477-
var outc byte
477+
var outc int
478478
for i := range 3 {
479479
c := in[ini+1+i]
480-
if c < '0' || c > '9' {
480+
if c < '0' || c > '7' {
481481
return outi, errInvalidEscape
482482
}
483483

484484
outc *= 8
485-
outc += c - '0'
485+
outc += int(c - '0')
486486
}
487487

488-
out[outi] = outc
488+
if outc > 0xFF {
489+
return outi, errInvalidEscape
490+
}
491+
out[outi] = byte(outc)
489492
outi++
490493

491494
ini += 4

src/internal/runtime/cgroup/cgroup_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,3 +682,23 @@ b/c`,
682682
}
683683
})
684684
}
685+
686+
func TestUnescapeInvalidPath(t *testing.T) {
687+
for _, in := range []string{
688+
`/a/b\c`,
689+
`/a/b\01`,
690+
`/a/b\018`,
691+
`/a/b\01c`,
692+
`/a/b\777`,
693+
`01234567890123456789`, // too long
694+
`\001\002\003\004\005\006\007\010\011`, // too long
695+
} {
696+
out := make([]byte, 8)
697+
t.Run(in, func(t *testing.T) {
698+
_, err := cgroup.UnescapePath(out, []byte(in))
699+
if err == nil {
700+
t.Errorf("unescapePath got nil err, want non-nil")
701+
}
702+
})
703+
}
704+
}

0 commit comments

Comments
 (0)