Skip to content

Commit d27041f

Browse files
committed
fix PACKET_remaining usage
1 parent 8e03315 commit d27041f

File tree

4 files changed

+60
-64
lines changed

4 files changed

+60
-64
lines changed

patches/openssl.OpenSSL_1_1_1-stable.patch

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h
2-
index 9af0c899..c77a04cd 100644
2+
index 9af0c8995e..c77a04cd90 100644
33
--- a/include/openssl/ssl.h
44
+++ b/include/openssl/ssl.h
55
@@ -1818,6 +1818,7 @@ size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
@@ -11,7 +11,7 @@ index 9af0c899..c77a04cd 100644
1111
const unsigned char **out, size_t *outlen);
1212

1313
diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h
14-
index 76d9fda4..a29114f2 100644
14+
index 76d9fda46e..a29114f215 100644
1515
--- a/include/openssl/tls1.h
1616
+++ b/include/openssl/tls1.h
1717
@@ -131,6 +131,15 @@ extern "C" {
@@ -31,10 +31,10 @@ index 76d9fda4..a29114f2 100644
3131
# define TLSEXT_TYPE_session_ticket 35
3232

3333
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
34-
index 47adc321..635b23b3 100644
34+
index 47adc3211c..be20746b98 100644
3535
--- a/ssl/ssl_lib.c
3636
+++ b/ssl/ssl_lib.c
37-
@@ -5219,6 +5219,95 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
37+
@@ -5219,6 +5219,94 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
3838
return 0;
3939
}
4040

@@ -74,11 +74,12 @@ index 47adc321..635b23b3 100644
7474
+ ptr += 2;
7575
+
7676
+ /* ciphers */
77-
+ num = PACKET_remaining(&s->clienthello->ciphersuites);
78-
+ *(uint16_t*)ptr = (uint16_t)num;
79-
+ ptr += 2;
80-
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81-
+ ptr += num;
77+
+ if (num = PACKET_remaining(&s->clienthello->ciphersuites)) {
78+
+ *(uint16_t*)ptr = (uint16_t)num;
79+
+ ptr += 2;
80+
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81+
+ ptr += num;
82+
+ }
8283
+
8384
+ /* extensions */
8485
+ num = 0;
@@ -104,19 +105,17 @@ index 47adc321..635b23b3 100644
104105
+ ptr += num*2;
105106
+
106107
+ /* groups */
107-
+ if (groups) {
108-
+ num = PACKET_remaining(groups);
108+
+ if (groups && (num = PACKET_remaining(groups))) {
109109
+ memcpy(ptr, PACKET_data(groups), num);
110110
+ *(uint16_t*)ptr = (uint16_t)num;
111111
+ ptr += num;
112112
+ } else {
113-
+ *(uint16_t*)ptr = 0;
114-
+ ptr += 2;
113+
+ *(uint16_t*)ptr = 0;
114+
+ ptr += 2;
115115
+ }
116116
+
117117
+ /* formats */
118-
+ if (formats) {
119-
+ num = PACKET_remaining(formats);
118+
+ if (formats && (num = PACKET_remaining(formats))) {
120119
+ memcpy(ptr, PACKET_data(formats), num);
121120
+ *ptr = (uint8_t)num;
122121
+ ptr += num;
@@ -131,7 +130,7 @@ index 47adc321..635b23b3 100644
131130
size_t *outlen)
132131
{
133132
diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h
134-
index 5c792154..a3038c79 100644
133+
index 5c79215423..a3038c79ea 100644
135134
--- a/ssl/ssl_local.h
136135
+++ b/ssl/ssl_local.h
137136
@@ -714,6 +714,10 @@ typedef enum tlsext_index_en {
@@ -146,7 +145,7 @@ index 5c792154..a3038c79 100644
146145
TLSEXT_IDX_psk,
147146
/* Dummy index - must always be the last entry */
148147
diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c
149-
index 0f39275b..7cb1e622 100644
148+
index 0f39275baa..7cb1e62287 100644
150149
--- a/ssl/statem/extensions.c
151150
+++ b/ssl/statem/extensions.c
152151
@@ -377,6 +377,38 @@ static const EXTENSION_DEFINITION ext_defs[] = {

patches/openssl.openssl-3.0.patch

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index 105b4a4a3c..6c7eb4643a 100644
1111
const unsigned char **out, size_t *outlen);
1212

1313
diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h
14-
index d6e9331fa1..b62b4e380d 100644
14+
index 91558fa8d1..b04e6ec4fa 100644
1515
--- a/include/openssl/tls1.h
1616
+++ b/include/openssl/tls1.h
1717
@@ -134,6 +134,15 @@ extern "C" {
@@ -31,10 +31,10 @@ index d6e9331fa1..b62b4e380d 100644
3131
# define TLSEXT_TYPE_session_ticket 35
3232

3333
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
34-
index 2c8479eb5f..4c62687258 100644
34+
index e628140dfa..512e5a552c 100644
3535
--- a/ssl/ssl_lib.c
3636
+++ b/ssl/ssl_lib.c
37-
@@ -5463,6 +5463,95 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
37+
@@ -5481,6 +5481,94 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
3838
return 0;
3939
}
4040

@@ -74,11 +74,12 @@ index 2c8479eb5f..4c62687258 100644
7474
+ ptr += 2;
7575
+
7676
+ /* ciphers */
77-
+ num = PACKET_remaining(&s->clienthello->ciphersuites);
78-
+ *(uint16_t*)ptr = (uint16_t)num;
79-
+ ptr += 2;
80-
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81-
+ ptr += num;
77+
+ if (num = PACKET_remaining(&s->clienthello->ciphersuites)) {
78+
+ *(uint16_t*)ptr = (uint16_t)num;
79+
+ ptr += 2;
80+
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81+
+ ptr += num;
82+
+ }
8283
+
8384
+ /* extensions */
8485
+ num = 0;
@@ -104,19 +105,17 @@ index 2c8479eb5f..4c62687258 100644
104105
+ ptr += num*2;
105106
+
106107
+ /* groups */
107-
+ if (groups) {
108-
+ num = PACKET_remaining(groups);
108+
+ if (groups && (num = PACKET_remaining(groups))) {
109109
+ memcpy(ptr, PACKET_data(groups), num);
110110
+ *(uint16_t*)ptr = (uint16_t)num;
111111
+ ptr += num;
112112
+ } else {
113-
+ *(uint16_t*)ptr = 0;
114-
+ ptr += 2;
113+
+ *(uint16_t*)ptr = 0;
114+
+ ptr += 2;
115115
+ }
116116
+
117117
+ /* formats */
118-
+ if (formats) {
119-
+ num = PACKET_remaining(formats);
118+
+ if (formats && (num = PACKET_remaining(formats))) {
120119
+ memcpy(ptr, PACKET_data(formats), num);
121120
+ *ptr = (uint8_t)num;
122121
+ ptr += num;
@@ -146,7 +145,7 @@ index 5fb1feb801..99f1370ea3 100644
146145
TLSEXT_IDX_psk,
147146
/* Dummy index - must always be the last entry */
148147
diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c
149-
index 1518ca7f4e..66a83bcb16 100644
148+
index f8157389b7..fb5e1a8453 100644
150149
--- a/ssl/statem/extensions.c
151150
+++ b/ssl/statem/extensions.c
152151
@@ -370,6 +370,38 @@ static const EXTENSION_DEFINITION ext_defs[] = {

patches/openssl.openssl-3.1.patch

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index f03f52fbd8..3140c3c5c5 100644
1111
const unsigned char **out, size_t *outlen);
1212

1313
diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h
14-
index 793155e186..ef1f187b15 100644
14+
index 03f43744b1..a54c78e1fe 100644
1515
--- a/include/openssl/tls1.h
1616
+++ b/include/openssl/tls1.h
1717
@@ -134,6 +134,15 @@ extern "C" {
@@ -31,10 +31,10 @@ index 793155e186..ef1f187b15 100644
3131
# define TLSEXT_TYPE_session_ticket 35
3232

3333
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
34-
index b5cc4af2f0..578598e664 100644
34+
index f218dcf1db..8bf43c4c58 100644
3535
--- a/ssl/ssl_lib.c
3636
+++ b/ssl/ssl_lib.c
37-
@@ -5464,6 +5464,95 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
37+
@@ -5482,6 +5482,94 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
3838
return 0;
3939
}
4040

@@ -74,11 +74,12 @@ index b5cc4af2f0..578598e664 100644
7474
+ ptr += 2;
7575
+
7676
+ /* ciphers */
77-
+ num = PACKET_remaining(&s->clienthello->ciphersuites);
78-
+ *(uint16_t*)ptr = (uint16_t)num;
79-
+ ptr += 2;
80-
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81-
+ ptr += num;
77+
+ if (num = PACKET_remaining(&s->clienthello->ciphersuites)) {
78+
+ *(uint16_t*)ptr = (uint16_t)num;
79+
+ ptr += 2;
80+
+ memcpy(ptr, PACKET_data(&s->clienthello->ciphersuites), num);
81+
+ ptr += num;
82+
+ }
8283
+
8384
+ /* extensions */
8485
+ num = 0;
@@ -104,19 +105,17 @@ index b5cc4af2f0..578598e664 100644
104105
+ ptr += num*2;
105106
+
106107
+ /* groups */
107-
+ if (groups) {
108-
+ num = PACKET_remaining(groups);
108+
+ if (groups && (num = PACKET_remaining(groups))) {
109109
+ memcpy(ptr, PACKET_data(groups), num);
110110
+ *(uint16_t*)ptr = (uint16_t)num;
111111
+ ptr += num;
112112
+ } else {
113-
+ *(uint16_t*)ptr = 0;
114-
+ ptr += 2;
113+
+ *(uint16_t*)ptr = 0;
114+
+ ptr += 2;
115115
+ }
116116
+
117117
+ /* formats */
118-
+ if (formats) {
119-
+ num = PACKET_remaining(formats);
118+
+ if (formats && (num = PACKET_remaining(formats))) {
120119
+ memcpy(ptr, PACKET_data(formats), num);
121120
+ *ptr = (uint8_t)num;
122121
+ ptr += num;
@@ -146,7 +145,7 @@ index 845329a809..8fa0619feb 100644
146145
TLSEXT_IDX_psk,
147146
/* Dummy index - must always be the last entry */
148147
diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c
149-
index e182b5abac..7d5adbf845 100644
148+
index 2ff809bc0f..fd730c09b8 100644
150149
--- a/ssl/statem/extensions.c
151150
+++ b/ssl/statem/extensions.c
152151
@@ -369,6 +369,38 @@ static const EXTENSION_DEFINITION ext_defs[] = {

patches/openssl.openssl-3.2.patch

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index 9f91039f8a..81b9c51892 100644
1111
size_t *num_exts);
1212
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
1313
diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h
14-
index 7e3d1a725b..ecee15e29f 100644
14+
index 5329338efa..9755b5f44c 100644
1515
--- a/include/openssl/tls1.h
1616
+++ b/include/openssl/tls1.h
1717
@@ -142,6 +142,13 @@ extern "C" {
@@ -29,10 +29,10 @@ index 7e3d1a725b..ecee15e29f 100644
2929
# define TLSEXT_TYPE_compress_certificate 27
3030

3131
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
32-
index 26cae27dae..f5d1d8013a 100644
32+
index a6695ca4a0..4af995af35 100644
3333
--- a/ssl/ssl_lib.c
3434
+++ b/ssl/ssl_lib.c
35-
@@ -6572,6 +6572,99 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
35+
@@ -6595,6 +6595,98 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
3636
return 0;
3737
}
3838

@@ -76,11 +76,12 @@ index 26cae27dae..f5d1d8013a 100644
7676
+ ptr += 2;
7777
+
7878
+ /* ciphers */
79-
+ num = PACKET_remaining(&sc->clienthello->ciphersuites);
80-
+ *(uint16_t*)ptr = (uint16_t)num;
81-
+ ptr += 2;
82-
+ memcpy(ptr, PACKET_data(&sc->clienthello->ciphersuites), num);
83-
+ ptr += num;
79+
+ if (num = PACKET_remaining(&sc->clienthello->ciphersuites)) {
80+
+ *(uint16_t*)ptr = (uint16_t)num;
81+
+ ptr += 2;
82+
+ memcpy(ptr, PACKET_data(&sc->clienthello->ciphersuites), num);
83+
+ ptr += num;
84+
+ }
8485
+
8586
+ /* extensions */
8687
+ num = 0;
@@ -106,19 +107,17 @@ index 26cae27dae..f5d1d8013a 100644
106107
+ ptr += num*2;
107108
+
108109
+ /* groups */
109-
+ if (groups) {
110-
+ num = PACKET_remaining(groups);
110+
+ if (groups && (num = PACKET_remaining(groups))) {
111111
+ memcpy(ptr, PACKET_data(groups), num);
112112
+ *(uint16_t*)ptr = (uint16_t)num;
113113
+ ptr += num;
114114
+ } else {
115-
+ *(uint16_t*)ptr = 0;
116-
+ ptr += 2;
115+
+ *(uint16_t*)ptr = 0;
116+
+ ptr += 2;
117117
+ }
118118
+
119119
+ /* formats */
120-
+ if (formats) {
121-
+ num = PACKET_remaining(formats);
120+
+ if (formats && (num = PACKET_remaining(formats))) {
122121
+ memcpy(ptr, PACKET_data(formats), num);
123122
+ *ptr = (uint8_t)num;
124123
+ ptr += num;
@@ -133,10 +132,10 @@ index 26cae27dae..f5d1d8013a 100644
133132
{
134133
RAW_EXTENSION *ext;
135134
diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h
136-
index 0d3acfbe66..01ceec6897 100644
135+
index 5f19e679fc..a5241e163d 100644
137136
--- a/ssl/ssl_local.h
138137
+++ b/ssl/ssl_local.h
139-
@@ -707,6 +707,9 @@ typedef enum tlsext_index_en {
138+
@@ -708,6 +708,9 @@ typedef enum tlsext_index_en {
140139
TLSEXT_IDX_compress_certificate,
141140
TLSEXT_IDX_early_data,
142141
TLSEXT_IDX_certificate_authorities,
@@ -147,7 +146,7 @@ index 0d3acfbe66..01ceec6897 100644
147146
TLSEXT_IDX_psk,
148147
/* Dummy index - must always be the last entry */
149148
diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c
150-
index 0a64ca2246..9460207d1f 100644
149+
index c35c2ccd33..55c04a9937 100644
151150
--- a/ssl/statem/extensions.c
152151
+++ b/ssl/statem/extensions.c
153152
@@ -411,6 +411,30 @@ static const EXTENSION_DEFINITION ext_defs[] = {

0 commit comments

Comments
 (0)