From: Ian Lance Taylor Date: Mon, 12 Feb 2024 03:54:52 +0000 (-0800) Subject: internal/safefilepath: use bytealg to search for zero byte X-Git-Tag: go1.23rc1~1240 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a5904142043e8998eaa15728150c48bcfdca7d5;p=gostls13.git internal/safefilepath: use bytealg to search for zero byte Change-Id: I20e72d421d89095c460495001969291b99cdf59e Reviewed-on: https://go-review.googlesource.com/c/go/+/563139 Reviewed-by: Ian Lance Taylor Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor --- diff --git a/src/internal/safefilepath/path_other.go b/src/internal/safefilepath/path_other.go index 974e7751a2..10971e8203 100644 --- a/src/internal/safefilepath/path_other.go +++ b/src/internal/safefilepath/path_other.go @@ -6,7 +6,10 @@ package safefilepath -import "runtime" +import ( + "internal/bytealg" + "runtime" +) func fromFS(path string) (string, error) { if runtime.GOOS == "plan9" { @@ -14,10 +17,8 @@ func fromFS(path string) (string, error) { return "", errInvalidPath } } - for i := range path { - if path[i] == 0 { - return "", errInvalidPath - } + if bytealg.IndexByteString(path, 0) >= 0 { + return "", errInvalidPath } return path, nil }