Skip to content

Commit a312d6f

Browse files
committed
fix AuthentiHash() out of bound access
1 parent ab23dac commit a312d6f

3 files changed

+10
-5
lines changed

security.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"fmt"
1717
"hash"
1818
"io"
19-
"io/ioutil"
2019
"os"
2120
"os/exec"
2221
"path/filepath"
@@ -72,7 +71,7 @@ type Certificate struct {
7271
Header WinCertificate `json:"header"`
7372
Content pkcs7.PKCS7 `json:"-"`
7473
SignatureContent AuthenticodeContent `json:"-"`
75-
SignatureValid bool `json:"-"`
74+
SignatureValid bool `json:"signature_valid"`
7675
Raw []byte `json:"-"`
7776
Info CertInfo `json:"info"`
7877
Verified bool `json:"verified"`
@@ -245,7 +244,11 @@ func (pe *File) parseLocations() (map[string]*RelRange, error) {
245244
// - The location of the entry of the Certificate Table in the Data Directory
246245
// - The location of the Certificate Table.
247246
func (pe *File) Authentihash() []byte {
248-
return pe.AuthentihashExt(crypto.SHA256.New())[0]
247+
results := pe.AuthentihashExt(crypto.SHA256.New())
248+
if len(results) > 0 {
249+
return results[0]
250+
}
251+
return nil
249252
}
250253

251254
// AuthentihashExt generates pe image file hashes using the given hashers.
@@ -494,7 +497,7 @@ func loadSystemRoots() (*x509.CertPool, error) {
494497
}
495498
}
496499

497-
files, err := ioutil.ReadDir(dir)
500+
files, err := os.ReadDir(dir)
498501
if err != nil {
499502
return roots, err
500503
}
@@ -504,7 +507,7 @@ func loadSystemRoots() (*x509.CertPool, error) {
504507
continue
505508
}
506509
certPath := filepath.Join(dir, f.Name())
507-
certData, err := ioutil.ReadFile(certPath)
510+
certData, err := os.ReadFile(certPath)
508511
if err != nil {
509512
return roots, err
510513
}

security_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func TestAuthentihash(t *testing.T) {
170170
"595e4eb556587a1363ff297df9f354a377963ecac0bed19230992b9601426aae"},
171171
{getAbsoluteFilePath("test/mfc40u.dll"),
172172
"5c8acdf9b2c7854c6b8e22e973d2fbae9c68fc22513d24c68c8e8010b1663e67"},
173+
{getAbsoluteFilePath("test/000057fd78f66e64e15f5070364c824a8923b6216bd8bcf6368857fb9674c483"),
174+
""},
173175
}
174176

175177
for _, tt := range tests {
Binary file not shown.

0 commit comments

Comments
 (0)