Skip to content

Commit 1c34e3e

Browse files
authored
Fix miscellaneous value/pointer receiver mismatches (#8652)
Update the Linter's Check and CheckCRL methods to use a pointer receiver, to match the fact that New returns a pointer to a Linter, and that the linter itself contains various large pointer/interface fields. Update Observer's Start() method to use a pointer receiver, to match the fact that obs_conf.MakeObserver returns a pointer. Update pcks11helper's MockCtx methods to use pointer receivers, to match the fact that NewMock returns a pointer. Update the VA's getAddrs method to use a pointer receiver, to match every other method on the VA. Do not update various MarshalJSON and UnmarshalJSON methods to match each other, since the expectation there is that all UnmarshalJSON methods use pointer receivers while all MarshalJSON methods use value receivers.
1 parent 4fe0a5a commit 1c34e3e

5 files changed

Lines changed: 21 additions & 20 deletions

File tree

linter/linter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func New(realIssuer *x509.Certificate, realSigner crypto.Signer) (*Linter, error
100100
// replaced with the linter's pubkey so that it appears self-signed. It returns
101101
// an error if any lint fails. On success it also returns the DER bytes of the
102102
// linting certificate.
103-
func (l Linter) Check(tbs *x509.Certificate, subjectPubKey crypto.PublicKey, reg lint.Registry) ([]byte, error) {
103+
func (l *Linter) Check(tbs *x509.Certificate, subjectPubKey crypto.PublicKey, reg lint.Registry) ([]byte, error) {
104104
lintPubKey := subjectPubKey
105105
selfSigned, err := core.PublicKeysEqual(subjectPubKey, l.realPubKey)
106106
if err != nil {
@@ -127,7 +127,7 @@ func (l Linter) Check(tbs *x509.Certificate, subjectPubKey crypto.PublicKey, reg
127127
// CheckCRL signs the given RevocationList template using the Linter's fake
128128
// issuer cert and private key, then runs the resulting CRL through all CRL
129129
// lints in the registry. It returns an error if any check fails.
130-
func (l Linter) CheckCRL(tbs *x509.RevocationList, reg lint.Registry) error {
130+
func (l *Linter) CheckCRL(tbs *x509.RevocationList, reg lint.Registry) error {
131131
crl, err := makeLintCRL(tbs, l.issuer, l.signer)
132132
if err != nil {
133133
return err

observer/observer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Observer struct {
2020
}
2121

2222
// Start spins off a goroutine for each monitor, and waits for a signal to exit
23-
func (o Observer) Start() {
23+
func (o *Observer) Start() {
2424
for _, mon := range o.monitors {
2525
go mon.start(o.logger)
2626
}

pkcs11helpers/helpers.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,34 +388,34 @@ type MockCtx struct {
388388
FindObjectsFinalFunc func(sh pkcs11.SessionHandle) error
389389
}
390390

391-
func (mc MockCtx) GenerateKeyPair(s pkcs11.SessionHandle, m []*pkcs11.Mechanism, a1 []*pkcs11.Attribute, a2 []*pkcs11.Attribute) (pkcs11.ObjectHandle, pkcs11.ObjectHandle, error) {
391+
func (mc *MockCtx) GenerateKeyPair(s pkcs11.SessionHandle, m []*pkcs11.Mechanism, a1 []*pkcs11.Attribute, a2 []*pkcs11.Attribute) (pkcs11.ObjectHandle, pkcs11.ObjectHandle, error) {
392392
return mc.GenerateKeyPairFunc(s, m, a1, a2)
393393
}
394394

395-
func (mc MockCtx) GetAttributeValue(s pkcs11.SessionHandle, o pkcs11.ObjectHandle, a []*pkcs11.Attribute) ([]*pkcs11.Attribute, error) {
395+
func (mc *MockCtx) GetAttributeValue(s pkcs11.SessionHandle, o pkcs11.ObjectHandle, a []*pkcs11.Attribute) ([]*pkcs11.Attribute, error) {
396396
return mc.GetAttributeValueFunc(s, o, a)
397397
}
398398

399-
func (mc MockCtx) SignInit(s pkcs11.SessionHandle, m []*pkcs11.Mechanism, o pkcs11.ObjectHandle) error {
399+
func (mc *MockCtx) SignInit(s pkcs11.SessionHandle, m []*pkcs11.Mechanism, o pkcs11.ObjectHandle) error {
400400
return mc.SignInitFunc(s, m, o)
401401
}
402402

403-
func (mc MockCtx) Sign(s pkcs11.SessionHandle, m []byte) ([]byte, error) {
403+
func (mc *MockCtx) Sign(s pkcs11.SessionHandle, m []byte) ([]byte, error) {
404404
return mc.SignFunc(s, m)
405405
}
406406

407-
func (mc MockCtx) GenerateRandom(s pkcs11.SessionHandle, c int) ([]byte, error) {
407+
func (mc *MockCtx) GenerateRandom(s pkcs11.SessionHandle, c int) ([]byte, error) {
408408
return mc.GenerateRandomFunc(s, c)
409409
}
410410

411-
func (mc MockCtx) FindObjectsInit(sh pkcs11.SessionHandle, temp []*pkcs11.Attribute) error {
411+
func (mc *MockCtx) FindObjectsInit(sh pkcs11.SessionHandle, temp []*pkcs11.Attribute) error {
412412
return mc.FindObjectsInitFunc(sh, temp)
413413
}
414414

415-
func (mc MockCtx) FindObjects(sh pkcs11.SessionHandle, max int) ([]pkcs11.ObjectHandle, bool, error) {
415+
func (mc *MockCtx) FindObjects(sh pkcs11.SessionHandle, max int) ([]pkcs11.ObjectHandle, bool, error) {
416416
return mc.FindObjectsFunc(sh, max)
417417
}
418418

419-
func (mc MockCtx) FindObjectsFinal(sh pkcs11.SessionHandle) error {
419+
func (mc *MockCtx) FindObjectsFinal(sh pkcs11.SessionHandle) error {
420420
return mc.FindObjectsFinalFunc(sh)
421421
}

pkcs11helpers/helpers_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
"strings"
1515
"testing"
1616

17-
"github.com/letsencrypt/boulder/test"
1817
"github.com/miekg/pkcs11"
18+
19+
"github.com/letsencrypt/boulder/test"
1920
)
2021

2122
func TestGetECDSAPublicKey(t *testing.T) {
@@ -151,7 +152,7 @@ func newSessionWithMock() (*Session, *MockCtx) {
151152
}
152153

153154
func TestFindObjectFailsOnFailedInit(t *testing.T) {
154-
ctx := MockCtx{}
155+
ctx := &MockCtx{}
155156
ctx.FindObjectsFinalFunc = findObjectsFinalOK
156157
ctx.FindObjectsFunc = func(pkcs11.SessionHandle, int) ([]pkcs11.ObjectHandle, bool, error) {
157158
return []pkcs11.ObjectHandle{1}, false, nil
@@ -167,7 +168,7 @@ func TestFindObjectFailsOnFailedInit(t *testing.T) {
167168
}
168169

169170
func TestFindObjectFailsOnFailedFindObjects(t *testing.T) {
170-
ctx := MockCtx{}
171+
ctx := &MockCtx{}
171172
ctx.FindObjectsInitFunc = findObjectsInitOK
172173
ctx.FindObjectsFinalFunc = findObjectsFinalOK
173174

@@ -181,7 +182,7 @@ func TestFindObjectFailsOnFailedFindObjects(t *testing.T) {
181182
}
182183

183184
func TestFindObjectFailsOnNoHandles(t *testing.T) {
184-
ctx := MockCtx{}
185+
ctx := &MockCtx{}
185186
ctx.FindObjectsInitFunc = findObjectsInitOK
186187
ctx.FindObjectsFinalFunc = findObjectsFinalOK
187188

@@ -195,7 +196,7 @@ func TestFindObjectFailsOnNoHandles(t *testing.T) {
195196
}
196197

197198
func TestFindObjectFailsOnMultipleHandles(t *testing.T) {
198-
ctx := MockCtx{}
199+
ctx := &MockCtx{}
199200
ctx.FindObjectsInitFunc = findObjectsInitOK
200201
ctx.FindObjectsFinalFunc = findObjectsFinalOK
201202

@@ -210,7 +211,7 @@ func TestFindObjectFailsOnMultipleHandles(t *testing.T) {
210211
}
211212

212213
func TestFindObjectFailsOnFinalizeFailure(t *testing.T) {
213-
ctx := MockCtx{}
214+
ctx := &MockCtx{}
214215
ctx.FindObjectsInitFunc = findObjectsInitOK
215216

216217
// test FindObject fails when FindObjectsFinal fails
@@ -226,7 +227,7 @@ func TestFindObjectFailsOnFinalizeFailure(t *testing.T) {
226227
}
227228

228229
func TestFindObjectSucceeds(t *testing.T) {
229-
ctx := MockCtx{}
230+
ctx := &MockCtx{}
230231
ctx.FindObjectsInitFunc = findObjectsInitOK
231232
ctx.FindObjectsFinalFunc = findObjectsFinalOK
232233
ctx.FindObjectsFunc = func(pkcs11.SessionHandle, int) ([]pkcs11.ObjectHandle, bool, error) {
@@ -241,7 +242,7 @@ func TestFindObjectSucceeds(t *testing.T) {
241242
}
242243

243244
func TestX509Signer(t *testing.T) {
244-
ctx := MockCtx{}
245+
ctx := &MockCtx{}
245246

246247
// test that x509Signer.Sign properly converts the PKCS#11 format signature to
247248
// the RFC 5480 format signature

va/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
// there is an error resolving the hostname, or if no usable IP addresses are
2727
// available then a berrors.DNSError instance is returned with a nil netip.Addr
2828
// slice.
29-
func (va ValidationAuthorityImpl) getAddrs(ctx context.Context, hostname string) ([]netip.Addr, []string, error) {
29+
func (va *ValidationAuthorityImpl) getAddrs(ctx context.Context, hostname string) ([]netip.Addr, []string, error) {
3030
// Kick off both the A and AAAA lookups in parallel.
3131
var wg sync.WaitGroup
3232

0 commit comments

Comments
 (0)