Skip to content

Commit 50dcffb

Browse files
rolandshoemakergopherbot
authored andcommitted
crypto/internal/boring: don't shadow named returns
In setupRSA we use named returns so that we can defer freeing of the boring private key and context, but were using returns of the form `return nil, nil, ...` which nil'd the named returns, preventing them from actually being freed. Update all of the returns to not shadow the named variables. Thanks to Quim Muntal of Microsoft for reporting this issue. Change-Id: Iaf0f0b17e123a7df730cb1e91a324fe622611f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/574195 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
1 parent b47f2fe commit 50dcffb

File tree

1 file changed

+14
-14
lines changed
  • src/crypto/internal/boring

1 file changed

+14
-14
lines changed

src/crypto/internal/boring/rsa.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,60 +126,60 @@ func setupRSA(withKey func(func(*C.GO_RSA) C.int) C.int,
126126

127127
pkey = C._goboringcrypto_EVP_PKEY_new()
128128
if pkey == nil {
129-
return nil, nil, fail("EVP_PKEY_new")
129+
return pkey, ctx, fail("EVP_PKEY_new")
130130
}
131131
if withKey(func(key *C.GO_RSA) C.int {
132132
return C._goboringcrypto_EVP_PKEY_set1_RSA(pkey, key)
133133
}) == 0 {
134-
return nil, nil, fail("EVP_PKEY_set1_RSA")
134+
return pkey, ctx, fail("EVP_PKEY_set1_RSA")
135135
}
136136
ctx = C._goboringcrypto_EVP_PKEY_CTX_new(pkey, nil)
137137
if ctx == nil {
138-
return nil, nil, fail("EVP_PKEY_CTX_new")
138+
return pkey, ctx, fail("EVP_PKEY_CTX_new")
139139
}
140140
if init(ctx) == 0 {
141-
return nil, nil, fail("EVP_PKEY_operation_init")
141+
return pkey, ctx, fail("EVP_PKEY_operation_init")
142142
}
143143
if C._goboringcrypto_EVP_PKEY_CTX_set_rsa_padding(ctx, padding) == 0 {
144-
return nil, nil, fail("EVP_PKEY_CTX_set_rsa_padding")
144+
return pkey, ctx, fail("EVP_PKEY_CTX_set_rsa_padding")
145145
}
146146
if padding == C.GO_RSA_PKCS1_OAEP_PADDING {
147147
md := hashToMD(h)
148148
if md == nil {
149-
return nil, nil, errors.New("crypto/rsa: unsupported hash function")
149+
return pkey, ctx, errors.New("crypto/rsa: unsupported hash function")
150150
}
151151
mgfMD := hashToMD(mgfHash)
152152
if mgfMD == nil {
153-
return nil, nil, errors.New("crypto/rsa: unsupported hash function")
153+
return pkey, ctx, errors.New("crypto/rsa: unsupported hash function")
154154
}
155155
if C._goboringcrypto_EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) == 0 {
156-
return nil, nil, fail("EVP_PKEY_set_rsa_oaep_md")
156+
return pkey, ctx, fail("EVP_PKEY_set_rsa_oaep_md")
157157
}
158158
if C._goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, mgfMD) == 0 {
159-
return nil, nil, fail("EVP_PKEY_set_rsa_mgf1_md")
159+
return pkey, ctx, fail("EVP_PKEY_set_rsa_mgf1_md")
160160
}
161161
// ctx takes ownership of label, so malloc a copy for BoringCrypto to free.
162162
clabel := (*C.uint8_t)(C._goboringcrypto_OPENSSL_malloc(C.size_t(len(label))))
163163
if clabel == nil {
164-
return nil, nil, fail("OPENSSL_malloc")
164+
return pkey, ctx, fail("OPENSSL_malloc")
165165
}
166166
copy((*[1 << 30]byte)(unsafe.Pointer(clabel))[:len(label)], label)
167167
if C._goboringcrypto_EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, clabel, C.size_t(len(label))) == 0 {
168-
return nil, nil, fail("EVP_PKEY_CTX_set0_rsa_oaep_label")
168+
return pkey, ctx, fail("EVP_PKEY_CTX_set0_rsa_oaep_label")
169169
}
170170
}
171171
if padding == C.GO_RSA_PKCS1_PSS_PADDING {
172172
if saltLen != 0 {
173173
if C._goboringcrypto_EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, C.int(saltLen)) == 0 {
174-
return nil, nil, fail("EVP_PKEY_set_rsa_pss_saltlen")
174+
return pkey, ctx, fail("EVP_PKEY_set_rsa_pss_saltlen")
175175
}
176176
}
177177
md := cryptoHashToMD(ch)
178178
if md == nil {
179-
return nil, nil, errors.New("crypto/rsa: unsupported hash function")
179+
return pkey, ctx, errors.New("crypto/rsa: unsupported hash function")
180180
}
181181
if C._goboringcrypto_EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) == 0 {
182-
return nil, nil, fail("EVP_PKEY_set_rsa_mgf1_md")
182+
return pkey, ctx, fail("EVP_PKEY_set_rsa_mgf1_md")
183183
}
184184
}
185185

0 commit comments

Comments
 (0)