aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/gnutls-CVE-2021-20231.patch
blob: 5186522eee372b7d511ad1d803ed0c8d8206c25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 15beb4b193b2714d88107e7dffca781798684e7e Mon Sep 17 00:00:00 2001
From: Daiki Ueno <ueno@gnu.org>
Date: Fri, 29 Jan 2021 14:06:05 +0100
Subject: [PATCH 1/2] key_share: avoid use-after-free around realloc

Signed-off-by: Daiki Ueno <ueno@gnu.org>
---
 lib/ext/key_share.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/ext/key_share.c b/lib/ext/key_share.c
index ab8abf8fe..a8c4bb5cf 100644
--- a/lib/ext/key_share.c
+++ b/lib/ext/key_share.c
@@ -664,14 +664,14 @@ key_share_send_params(gnutls_session_t session,
 {
 	unsigned i;
 	int ret;
-	unsigned char *lengthp;
-	unsigned int cur_length;
 	unsigned int generated = 0;
 	const gnutls_group_entry_st *group;
 	const version_entry_st *ver;
 
 	/* this extension is only being sent on client side */
 	if (session->security_parameters.entity == GNUTLS_CLIENT) {
+		unsigned int length_pos;
+
 		ver = _gnutls_version_max(session);
 		if (unlikely(ver == NULL || ver->key_shares == 0))
 			return 0;
@@ -679,16 +679,13 @@ key_share_send_params(gnutls_session_t session,
 		if (!have_creds_for_tls13(session))
 			return 0;
 
-		/* write the total length later */
-		lengthp = &extdata->data[extdata->length];
+		length_pos = extdata->length;
 
 		ret =
 		    _gnutls_buffer_append_prefix(extdata, 16, 0);
 		if (ret < 0)
 			return gnutls_assert_val(ret);
 
-		cur_length = extdata->length;
-
 		if (session->internals.hsk_flags & HSK_HRR_RECEIVED) { /* we know the group */
 			group = get_group(session);
 			if (unlikely(group == NULL))
@@ -736,7 +733,8 @@ key_share_send_params(gnutls_session_t session,
 		}
 
 		/* copy actual length */
-		_gnutls_write_uint16(extdata->length - cur_length, lengthp);
+		_gnutls_write_uint16(extdata->length - length_pos - 2,
+				     &extdata->data[length_pos]);
 
 	} else { /* server */
 		ver = get_version(session);
-- 
2.30.2