]> Cypherpunks repositories - gostls13.git/commitdiff
internal/safefilepath: use bytealg to search for zero byte
authorIan Lance Taylor <iant@golang.org>
Mon, 12 Feb 2024 03:54:52 +0000 (19:54 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 13 Feb 2024 05:02:46 +0000 (05:02 +0000)
Change-Id: I20e72d421d89095c460495001969291b99cdf59e
Reviewed-on: https://go-review.googlesource.com/c/go/+/563139
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/internal/safefilepath/path_other.go

index 974e7751a290e682487a89ef1a0e2d963d148928..10971e820329140122f49c7c36ffac9691ffdc3d 100644 (file)
@@ -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
 }