1
0

Remove spurious fmt.Printf calls including one of a key (#15344)

And add a semgrep for fmt.Printf/Println.
This commit is contained in:
Christopher Swenson 2022-05-19 12:27:02 -07:00 committed by GitHub
parent cbdf16c5a1
commit 38b0fa6b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 8 deletions

View File

@ -198,7 +198,6 @@ func (a *AzureAuth) getJWT() (string, error) {
func getMetadata() (metadataJSON, error) {
metadataEndpoint, err := url.Parse(fmt.Sprintf("%s/metadata/instance", metadataEndpoint))
if err != nil {
fmt.Println("Error creating URL: ", err)
return metadataJSON{}, err
}

View File

@ -60,7 +60,6 @@ func (eci encryptedContentInfo) decrypt(key []byte) ([]byte, error) {
!alg.Equal(OIDEncryptionAlgorithmAES128CBC) &&
!alg.Equal(OIDEncryptionAlgorithmAES128GCM) &&
!alg.Equal(OIDEncryptionAlgorithmAES256GCM) {
fmt.Printf("Unsupported Content Encryption Algorithm: %s\n", alg)
return nil, ErrUnsupportedAlgorithm
}

View File

@ -5,7 +5,6 @@ package pkcs7
import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"os/exec"
@ -108,7 +107,7 @@ but that's not what ships are built for.
if err != nil {
t.Fatal(err)
}
fmt.Printf("%s\n", pemSignature)
t.Logf("%s\n", pemSignature)
derBlock, _ := pem.Decode(pemSignature)
if derBlock == nil {
t.Fatalf("failed to read DER block from signature PEM %s", tmpSignedFile.Name())

View File

@ -74,7 +74,6 @@ func (b *backend) pathCredsRead(ctx context.Context, req *logical.Request, d *fr
if err != nil {
return nil, fmt.Errorf("failed to generate username: %w", err)
}
fmt.Printf("username: %s\n", username)
password, err := b.generatePassword(ctx, config.PasswordPolicy)
if err != nil {

View File

@ -320,7 +320,6 @@ func testParseEntropy(t *testing.T, oss bool) {
case err != test.outErr:
t.Fatalf("error mismatch: expected %#v got %#v", err, test.outErr)
case err == nil && config.Entropy != nil && *config.Entropy != test.outEntropy:
fmt.Printf("\n config.Entropy: %#v", config.Entropy)
t.Fatalf("entropy config mismatch: expected %#v got %#v", test.outEntropy, *config.Entropy)
}
}

View File

@ -6,7 +6,6 @@ import (
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
@ -90,7 +89,6 @@ func DeriveSharedKey(secret, ourPublic, theirPublic []byte) ([]byte, error) {
if n != 32 {
return nil, errors.New("short read from hkdf")
}
fmt.Printf("Key: %s\n", hex.EncodeToString(key[:]))
return key[:], nil
}

View File

@ -0,0 +1,16 @@
rules:
- id: fmt.Printf
languages: [go]
message: fmt.Printf/Println is forbidden outside of cmd and test files
patterns:
- pattern-either:
- pattern: fmt.Printf
- pattern: fmt.Println
severity: ERROR
paths:
exclude:
- "*_test.go"
- "cmd/*.go"
- "cmd/**/*.go"
- sdk/database/dbplugin/server.go # effectively a cmd
- sdk/database/dbplugin/v5/plugin_server.go # effectively a cmd