Skip to content

Commit 9527d85

Browse files
committed
fix: Correctly test for a symlink uniget-org/backlog#113
1 parent 8592f86 commit 9527d85

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

cmd/uniget/hooks.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ var editHooksCmd = &cobra.Command{
239239
if !strings.HasPrefix(hookFileAbs, hooksDir) {
240240
return fmt.Errorf("hook file %s is outside of hookDir %s", hookFile, hooksDir)
241241
}
242-
_, err = os.Lstat(hookFile)
243-
if err == nil {
242+
243+
hookFileInfo, err := os.Lstat(hookFile)
244+
if err != nil {
245+
return fmt.Errorf("unable to stat hook file %s: %w", hookFile, err)
246+
}
247+
if hookFileInfo.Mode()&os.ModeSymlink != 0 {
244248
return fmt.Errorf("hook file %s is a symlink, which is not allowed for security reasons", hookFile)
245249
}
246250

@@ -443,8 +447,11 @@ func processHooks(path string, callback func(file string) error) error {
443447
}
444448

445449
hookFile := path + "/" + file.Name()
446-
_, err := os.Lstat(hookFile)
447-
if err == nil {
450+
hookFileInfo, err := os.Lstat(hookFile)
451+
if err != nil {
452+
return fmt.Errorf("unable to stat hook file %s: %w", hookFile, err)
453+
}
454+
if hookFileInfo.Mode()&os.ModeSymlink != 0 {
448455
return fmt.Errorf("hook file %s is a symlink, which is not allowed for security reasons", hookFile)
449456
}
450457

0 commit comments

Comments
 (0)