[go] internal/runtime/cgroup: stricter unescapePath

6 views
Skip to first unread message

胡玮文 (Gerrit)

unread,
Nov 21, 2025, 10:35:29 PM (8 days ago) Nov 21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

胡玮文 has uploaded the change for review

Commit message

internal/runtime/cgroup: stricter unescapePath

unescapePath now returns error when the path is too long, to avoid panic if
we got a really long path from mountinfo.

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

Change diff

diff --git a/src/internal/runtime/cgroup/cgroup.go b/src/internal/runtime/cgroup/cgroup.go
index f2e9da3..428c188 100644
--- a/src/internal/runtime/cgroup/cgroup.go
+++ b/src/internal/runtime/cgroup/cgroup.go
@@ -396,7 +396,10 @@
return len(target) == i || target[i] == '/' // must match at path boundary
}

-var errInvalidEscape error = stringError("invalid path escape sequence")
+var (
+ errInvalidEscape error = stringError("invalid path escape sequence")
+ errPathTooLong error = stringError("path too long")
+)

// unescapePath copies in to out, unescaping escape sequences generated by
// Linux's show_path.
@@ -410,14 +413,11 @@
//
// Also see escapePath in cgroup_linux_test.go.
func unescapePath(out []byte, in []byte) (int, error) {
- // Not strictly necessary, but simplifies the implementation and will
- // always hold in users.
- if len(out) < len(in) {
- throw("output too small")
- }
-
var outi, ini int
for ini < len(in) {
+ if outi >= len(out) {
+ return outi, errPathTooLong
+ }
c := in[ini]
if c != '\\' {
out[outi] = c
@@ -434,18 +434,21 @@
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 6d4fe12..001e374 100644
--- a/src/internal/runtime/cgroup/cgroup_test.go
+++ b/src/internal/runtime/cgroup/cgroup_test.go
@@ -543,3 +543,23 @@
}
})
}
+
+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")
+ }
+ })
+ }
+}

Change information

Files:
  • M src/internal/runtime/cgroup/cgroup.go
  • M src/internal/runtime/cgroup/cgroup_test.go
Change size: S
Delta: 2 files changed, 34 insertions(+), 11 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
Gerrit-Change-Number: 723242
Gerrit-PatchSet: 1
Gerrit-Owner: 胡玮文 <huw...@outlook.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

胡玮文 (Gerrit)

unread,
Nov 21, 2025, 10:42:16 PM (8 days ago) Nov 21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

胡玮文 uploaded new patchset

胡玮文 uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
Gerrit-Change-Number: 723242
Gerrit-PatchSet: 2
Gerrit-Owner: 胡玮文 <huw...@outlook.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

胡玮文 (Gerrit)

unread,
Nov 22, 2025, 4:16:26 AM (8 days ago) Nov 22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Carlos Amedee, Cherry Mui and Michael Knyszek

胡玮文 uploaded new patchset

胡玮文 uploaded patch set #4 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Carlos Amedee
  • Cherry Mui
  • Michael Knyszek
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
Gerrit-Change-Number: 723242
Gerrit-PatchSet: 4
Gerrit-Owner: 胡玮文 <huw...@outlook.com>
Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Attention: Carlos Amedee <car...@golang.org>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Pratt (Gerrit)

unread,
Nov 25, 2025, 11:38:11 AM (4 days ago) Nov 25
to 胡玮文, goph...@pubsubhelper.golang.org, Michael Pratt, Carlos Amedee, Cherry Mui, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Carlos Amedee, Cherry Mui, Michael Knyszek and 胡玮文

Michael Pratt voted

Auto-Submit+1
Code-Review+2
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Carlos Amedee
  • Cherry Mui
  • Michael Knyszek
  • 胡玮文
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
Gerrit-Change-Number: 723242
Gerrit-PatchSet: 5
Gerrit-Owner: 胡玮文 <huw...@outlook.com>
Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: 胡玮文 <huw...@outlook.com>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Attention: Carlos Amedee <car...@golang.org>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
Gerrit-Comment-Date: Tue, 25 Nov 2025 16:38:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

胡玮文 (Gerrit)

unread,
Nov 25, 2025, 10:48:52 PM (4 days ago) Nov 25
to goph...@pubsubhelper.golang.org, Go LUCI, Michael Pratt, Carlos Amedee, Cherry Mui, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Carlos Amedee, Cherry Mui, Michael Knyszek and Michael Pratt

胡玮文 added 1 comment

Patchset-level comments
File-level comment, Patchset 5 (Latest):
胡玮文 . resolved

Let's wait for the previous CLs merge. The added unit tests depends on them.

Open in Gerrit

Related details

Attention is currently required from:
  • Carlos Amedee
  • Cherry Mui
  • Michael Knyszek
  • Michael Pratt
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
Gerrit-Change-Number: 723242
Gerrit-PatchSet: 5
Gerrit-Owner: 胡玮文 <huw...@outlook.com>
Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Attention: Michael Pratt <mpr...@google.com>
Gerrit-Attention: Carlos Amedee <car...@golang.org>
Gerrit-Attention: Michael Knyszek <mkny...@google.com>
Gerrit-Comment-Date: Wed, 26 Nov 2025 03:48:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Dmitri Shuralyov (Gerrit)

unread,
Nov 27, 2025, 1:10:32 AM (3 days ago) Nov 27
to 胡玮文, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Go LUCI, Michael Pratt, Carlos Amedee, Cherry Mui, Michael Knyszek, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Carlos Amedee, Cherry Mui and Michael Knyszek

Dmitri Shuralyov voted

Auto-Submit+1
Code-Review+1
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Carlos Amedee
  • Cherry Mui
  • Michael Knyszek
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
    Gerrit-Change-Number: 723242
    Gerrit-PatchSet: 6
    Gerrit-Owner: 胡玮文 <huw...@outlook.com>
    Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
    Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Attention: Carlos Amedee <car...@golang.org>
    Gerrit-Attention: Michael Knyszek <mkny...@google.com>
    Gerrit-Comment-Date: Thu, 27 Nov 2025 06:10:29 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Nov 27, 2025, 1:29:55 AM (3 days ago) Nov 27
    to 胡玮文, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Dmitri Shuralyov, Dmitri Shuralyov, Michael Pratt, Carlos Amedee, Cherry Mui, Michael Knyszek, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Unreviewed changes

    5 is the latest approved patch-set.
    No files were changed between the latest approved patch-set and the submitted one.

    Change information

    Commit message:
    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-by: Dmitri Shuralyov <dmit...@google.com>
    Reviewed-by: Michael Pratt <mpr...@google.com>
    Auto-Submit: Dmitri Shuralyov <dmit...@google.com>
    Files:
    • M src/internal/runtime/cgroup/cgroup.go
    • M src/internal/runtime/cgroup/cgroup_test.go
    Change size: S
    Delta: 2 files changed, 27 insertions(+), 4 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by Dmitri Shuralyov, +2 by Michael Pratt
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3fdebce1d054c44919f0e66a33c778b5a2b099e2
    Gerrit-Change-Number: 723242
    Gerrit-PatchSet: 7
    Gerrit-Owner: 胡玮文 <huw...@outlook.com>
    Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages