Skip to content

Commit 349ba1f

Browse files
Fix nil pointer dereference
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
1 parent 87943db commit 349ba1f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

cmd/garm-cli/cmd/github_credentials.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package cmd
1616

1717
import (
18-
"crypto/x509"
19-
"encoding/pem"
2018
"fmt"
2119
"os"
2220
"strconv"
@@ -260,20 +258,20 @@ func init() {
260258
}
261259

262260
func parsePrivateKeyFromPath(path string) ([]byte, error) {
263-
if _, err := os.Stat(path); err != nil {
264-
return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath)
265-
}
261+
// if _, err := os.Stat(path); err != nil {
262+
// return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath)
263+
// }
266264
keyContents, err := os.ReadFile(path)
267265
if err != nil {
268266
return nil, fmt.Errorf("failed to read private key file: %w", err)
269267
}
270-
pemBlock, _ := pem.Decode(keyContents)
271-
if pemBlock == nil {
272-
return nil, fmt.Errorf("failed to decode PEM block")
273-
}
274-
if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil {
275-
return nil, fmt.Errorf("failed to parse private key: %w", err)
276-
}
268+
// pemBlock, _ := pem.Decode(keyContents)
269+
// if pemBlock == nil {
270+
// return nil, fmt.Errorf("failed to decode PEM block")
271+
// }
272+
// if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil {
273+
// return nil, fmt.Errorf("failed to parse private key: %w", err)
274+
// }
277275
return keyContents, nil
278276
}
279277

params/requests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ func (g GithubApp) Validate() error {
424424
}
425425

426426
block, _ := pem.Decode(g.PrivateKeyBytes)
427+
if block == nil {
428+
return runnerErrors.NewBadRequestError("invalid private_key_bytes")
429+
}
427430
// Parse the private key as PCKS1
428431
_, err := x509.ParsePKCS1PrivateKey(block.Bytes)
429432
if err != nil {

0 commit comments

Comments
 (0)