X Tutup
Skip to content

Commit 25b45a4

Browse files
rikingjsha
authored andcommitted
Errcheck errors fixed (letsencrypt#1677)
* Fix all errcheck errors * Add errcheck to test.sh * Add a new sa.Rollback method to make handling errors in rollbacks easier. This also causes a behavior change in the VA. If a HTTP connection is abruptly closed after serving the headers for a non-200 response, the reported error will be the read failure instead of the non-200.
1 parent e1622fd commit 25b45a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+387
-187
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ env:
5555
global:
5656
- LETSENCRYPT_PATH=$HOME/letsencrypt
5757
matrix:
58-
- RUN="integration vet lint fmt migrations"
58+
- RUN="integration vet lint fmt errcheck migrations"
5959
# Config changes that have landed in master but not yet been applied to
6060
# production can be made in boulder-config-next.json.
6161
- RUN="integration" BOULDER_CONFIG="test/boulder-config-next.json"

akamai/cache-client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ func (cpc *CachePurgeClient) purge(urls []string) error {
188188
if resp.Body == nil {
189189
return fmt.Errorf("No response body")
190190
}
191-
defer resp.Body.Close()
192191
body, err := ioutil.ReadAll(resp.Body)
192+
if err != nil {
193+
_ = resp.Body.Close()
194+
return err
195+
}
196+
err = resp.Body.Close()
193197
if err != nil {
194198
return err
195199
}

bdns/dns_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ func mockDNSQuery(w dns.ResponseWriter, r *dns.Msg) {
130130
}
131131
}
132132

133-
w.WriteMsg(m)
133+
err := w.WriteMsg(m)
134+
if err != nil {
135+
panic(err) // running tests, so panic is OK
136+
}
134137
return
135138
}
136139

ca/certificate-authority.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ func (ca *CertificateAuthorityImpl) IssueCertificate(csr x509.CertificateRequest
599599
}
600600

601601
// Submit the certificate to any configured CT logs
602-
go ca.Publisher.SubmitToCT(certDER)
602+
go func() {
603+
_ = ca.Publisher.SubmitToCT(certDER)
604+
}()
603605

604606
// Do not return an err at this point; caller must know that the Certificate
605607
// was issued. (Also, it should be impossible for err to be non-nil here)

cmd/admin-revoker/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,13 @@ func main() {
164164

165165
tx, err := dbMap.Begin()
166166
if err != nil {
167-
tx.Rollback()
167+
cmd.FailOnError(sa.Rollback(tx, err), "Couldn't begin transaction")
168168
}
169-
cmd.FailOnError(err, "Couldn't begin transaction")
170169

171170
err = revokeBySerial(serial, core.RevocationCode(reasonCode), deny, cac, logger, tx)
172171
if err != nil {
173-
tx.Rollback()
172+
cmd.FailOnError(sa.Rollback(tx, err), "Couldn't revoke certificate")
174173
}
175-
cmd.FailOnError(err, "Couldn't revoke certificate")
176174

177175
err = tx.Commit()
178176
cmd.FailOnError(err, "Couldn't cleanly close transaction")
@@ -195,9 +193,8 @@ func main() {
195193

196194
tx, err := dbMap.Begin()
197195
if err != nil {
198-
tx.Rollback()
196+
cmd.FailOnError(sa.Rollback(tx, err), "Couldn't begin transaction")
199197
}
200-
cmd.FailOnError(err, "Couldn't begin transaction")
201198

202199
_, err = sac.GetRegistration(regID)
203200
if err != nil {
@@ -206,9 +203,8 @@ func main() {
206203

207204
err = revokeByReg(regID, core.RevocationCode(reasonCode), deny, cac, logger, tx)
208205
if err != nil {
209-
tx.Rollback()
206+
cmd.FailOnError(sa.Rollback(tx, err), "Couldn't revoke certificate")
210207
}
211-
cmd.FailOnError(err, "Couldn't revoke certificate")
212208

213209
err = tx.Commit()
214210
cmd.FailOnError(err, "Couldn't cleanly close transaction")

cmd/boulder-ca/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ func main() {
152152

153153
cas, err := rpc.NewAmqpRPCServer(amqpConf, c.CA.MaxConcurrentRPCServerRequests, stats)
154154
cmd.FailOnError(err, "Unable to create CA RPC server")
155-
rpc.NewCertificateAuthorityServer(cas, cai)
155+
err = rpc.NewCertificateAuthorityServer(cas, cai)
156+
cmd.FailOnError(err, "Unable to setup CA RPC server")
156157

157158
err = cas.Start(amqpConf)
158159
cmd.FailOnError(err, "Unable to run CA RPC server")

cmd/boulder-publisher/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func main() {
5252

5353
pubs, err := rpc.NewAmqpRPCServer(amqpConf, c.Publisher.MaxConcurrentRPCServerRequests, stats)
5454
cmd.FailOnError(err, "Unable to create Publisher RPC server")
55-
rpc.NewPublisherServer(pubs, pubi)
55+
err = rpc.NewPublisherServer(pubs, pubi)
56+
cmd.FailOnError(err, "Unable to setup Publisher RPC server")
5657

5758
err = pubs.Start(amqpConf)
5859
cmd.FailOnError(err, "Unable to run Publisher RPC server")

cmd/boulder-ra/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ func main() {
8989

9090
ras, err := rpc.NewAmqpRPCServer(amqpConf, c.RA.MaxConcurrentRPCServerRequests, stats)
9191
cmd.FailOnError(err, "Unable to create RA RPC server")
92-
rpc.NewRegistrationAuthorityServer(ras, rai)
92+
err = rpc.NewRegistrationAuthorityServer(ras, rai)
93+
cmd.FailOnError(err, "Unable to setup RA RPC server")
9394

9495
err = ras.Start(amqpConf)
9596
cmd.FailOnError(err, "Unable to run RA RPC server")

cmd/boulder-sa/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func main() {
3434
amqpConf := saConf.AMQP
3535
sas, err := rpc.NewAmqpRPCServer(amqpConf, c.SA.MaxConcurrentRPCServerRequests, stats)
3636
cmd.FailOnError(err, "Unable to create SA RPC server")
37-
rpc.NewStorageAuthorityServer(sas, sai)
37+
err = rpc.NewStorageAuthorityServer(sas, sai)
38+
cmd.FailOnError(err, "Unable to setup SA RPC server")
3839

3940
err = sas.Start(amqpConf)
4041
cmd.FailOnError(err, "Unable to run SA RPC server")

cmd/boulder-va/gsb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func newGoogleSafeBrowsing(gsb *cmd.GoogleSafeBrowsingConfig) va.SafeBrowsing {
3636
}
3737
cmd.FailOnError(err, "unable to open Google Safe Browsing data directory")
3838
}
39-
f.Close()
39+
err = f.Close()
40+
cmd.FailOnError(err, "unable to access Google Safe Browsing data directory")
4041
sbc, err := safebrowsing.NewSafeBrowsing(gsb.APIKey, gsb.DataDir)
4142
if err != nil {
4243
cmd.FailOnError(err, "unable to create new safe browsing client")

0 commit comments

Comments
 (0)
X Tutup