From 3e794cf991fd0e28814b90aad191ec1cba652c60 Mon Sep 17 00:00:00 2001 From: kesonan Date: Sun, 17 Mar 2024 10:21:36 +0800 Subject: [PATCH] (goctl)fix code_ql (#4009) --- tools/goctl/util/zipx/zipx.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/goctl/util/zipx/zipx.go b/tools/goctl/util/zipx/zipx.go index 2b1619dde..0071150d1 100644 --- a/tools/goctl/util/zipx/zipx.go +++ b/tools/goctl/util/zipx/zipx.go @@ -16,10 +16,15 @@ func Unpacking(name, destPath string, mapper func(f *zip.File) bool) error { } defer r.Close() + destAbsPath, err := filepath.Abs(destPath) + if err != nil { + return err + } + for _, file := range r.File { ok := mapper(file) if ok { - err = fileCopy(file, destPath) + err = fileCopy(file, destAbsPath) if err != nil { return err } @@ -34,7 +39,12 @@ func fileCopy(file *zip.File, destPath string) error { return err } defer rc.Close() - filename := filepath.Join(destPath, filepath.Base(file.Name)) + abs, err := filepath.Abs(file.Name) + if err != nil { + return err + } + + filename := filepath.Join(destPath, filepath.Base(abs)) dir := filepath.Dir(filename) err = pathx.MkdirIfNotExist(dir) if err != nil {