Skip to content

Commit

Permalink
Add filepath sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
s1061123 committed Apr 15, 2024
1 parent 48769d9 commit d6174d6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"syscall"
"time"

Expand Down Expand Up @@ -111,10 +112,16 @@ func main() {
oldHashVal := ""
for {
hasher := sha512.New()
s, err := ioutil.ReadFile(*cert)
certPath, err := filepath.Abs(*cert)
if err != nil {
glog.Fatalf("illegal path %s in certPath: %s: %v", *cert, certPath, err)
os.Exit(1)
}
s, err := ioutil.ReadFile(certPath)
hasher.Write(s)
if err != nil {
glog.Fatalf("failed to read file %s: %v", *cert, err)
os.Exit(1)
}
newHashVal := hex.EncodeToString(hasher.Sum(nil))
if oldHashVal != "" && newHashVal != oldHashVal {
Expand Down

0 comments on commit d6174d6

Please sign in to comment.