Skip to content

Commit

Permalink
Update getChecksumFromHashFile to check split length of checksum file.
Browse files Browse the repository at this point in the history
This avoids referencing non-existent index for malformed file
  • Loading branch information
MatthewJohn committed May 29, 2024
1 parent dbc10af commit 631404f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bufio"
"crypto/sha256"
"encoding/hex"
"golang.org/x/crypto/openpgp"
"io"
"os"
"path/filepath"
"strings"

"golang.org/x/crypto/openpgp"
)

// getChecksumFromFile Extract the checksum from the signature file
Expand All @@ -24,7 +25,7 @@ func getChecksumFromHashFile(signatureFilePath string, terraformFileName string)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
split := strings.Split(scanner.Text(), " ")
if split[1] == terraformFileName {
if len(split) == 2 && split[1] == terraformFileName {
return split[0], nil
}
}
Expand Down

0 comments on commit 631404f

Please sign in to comment.