Skip to content

Commit ad1ca77

Browse files
committed
Check the plaintext buffer is large enough when decrypting SM2
Previously there was no check that the supplied buffer was large enough. It was just assumed to be sufficient. Instead we should check and fail if not. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
1 parent d07036b commit ad1ca77

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

crypto/sm2/sm2_crypt.c

+4
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -312,6 +312,10 @@ int ossl_sm2_decrypt(const EC_KEY *key,
312
C2 = sm2_ctext->C2->data;
312
C2 = sm2_ctext->C2->data;
313
C3 = sm2_ctext->C3->data;
313
C3 = sm2_ctext->C3->data;
314
msg_len = sm2_ctext->C2->length;
314
msg_len = sm2_ctext->C2->length;
315+
if (*ptext_len < (size_t)msg_len) {
316+
SM2err(SM2_F_SM2_DECRYPT, SM2_R_BUFFER_TOO_SMALL);
317+
goto done;
318+
}
315

319

316
ctx = BN_CTX_new_ex(libctx);
320
ctx = BN_CTX_new_ex(libctx);
317
if (ctx == NULL) {
321
if (ctx == NULL) {

0 commit comments

Comments
 (0)