Skip to content

Commit a8ed0ca

Browse files
committed
check the binary before opening, but disable G304
1 parent 535131e commit a8ed0ca

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

dbos/dbos.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"io"
1616
"log/slog"
1717
"os"
18+
"path/filepath"
1819
"sync"
1920
"sync/atomic"
2021
"time"
@@ -438,7 +439,20 @@ func getBinaryHash() (string, error) {
438439
return "", err
439440
}
440441

441-
file, err := os.Open(execPath)
442+
execPath, err = filepath.EvalSymlinks(execPath)
443+
if err != nil {
444+
return "", fmt.Errorf("resolve self path: %w", err)
445+
}
446+
447+
fi, err := os.Lstat(execPath)
448+
if err != nil {
449+
return "", err
450+
}
451+
if !fi.Mode().IsRegular() {
452+
return "", fmt.Errorf("executable is not a regular file")
453+
}
454+
455+
file, err := os.Open(execPath) // #nosec G304 -- opening our own executable, not user-supplied
442456
if err != nil {
443457
return "", err
444458
}

0 commit comments

Comments
 (0)