From 2a5904142043e8998eaa15728150c48bcfdca7d5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 11 Feb 2024 19:54:52 -0800 Subject: [PATCH] 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 --- src/internal/safefilepath/path_other.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 } -- 2.48.1