openssl: update to version 1.1.1a
[openwrt/staging/jogo.git] / package / libs / openssl / patches / 220-eng_devcrypto-fix-copy-of-unitilialized-digest.patch
1 From 68b02a8ab798b7e916c8141a36ab69d7493fc707 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cote2004-github@yahoo.com>
3 Date: Wed, 14 Nov 2018 13:58:06 -0200
4 Subject: [PATCH 3/7] eng_devcrypto: fix copy of unitilialized digest
5
6 If the source ctx has not been initialized, don't initialize the copy
7 either.
8
9 Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
10
11 Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
12 Reviewed-by: Richard Levitte <levitte@openssl.org>
13 (Merged from https://github.com/openssl/openssl/pull/7585)
14
15 (cherry picked from commit ae8183690fa53b978d4647563f5a521c4cafe94c)
16
17 --- a/crypto/engine/eng_devcrypto.c
18 +++ b/crypto/engine/eng_devcrypto.c
19 @@ -338,7 +338,8 @@ static int devcrypto_ciphers(ENGINE *e,
20
21 struct digest_ctx {
22 struct session_op sess;
23 - int init;
24 + /* This signals that the init function was called, not that it succeeded. */
25 + int init_called;
26 };
27
28 static const struct digest_data_st {
29 @@ -403,7 +404,7 @@ static int digest_init(EVP_MD_CTX *ctx)
30 const struct digest_data_st *digest_d =
31 get_digest_data(EVP_MD_CTX_type(ctx));
32
33 - digest_ctx->init = 1;
34 + digest_ctx->init_called = 1;
35
36 memset(&digest_ctx->sess, 0, sizeof(digest_ctx->sess));
37 digest_ctx->sess.mac = digest_d->devcryptoid;
38 @@ -476,14 +477,9 @@ static int digest_copy(EVP_MD_CTX *to, c
39 (struct digest_ctx *)EVP_MD_CTX_md_data(to);
40 struct cphash_op cphash;
41
42 - if (digest_from == NULL)
43 + if (digest_from == NULL || digest_from->init_called != 1)
44 return 1;
45
46 - if (digest_from->init != 1) {
47 - SYSerr(SYS_F_IOCTL, EINVAL);
48 - return 0;
49 - }
50 -
51 if (!digest_init(to)) {
52 SYSerr(SYS_F_IOCTL, errno);
53 return 0;