File tree 4 files changed +37
-25
lines changed
4 files changed +37
-25
lines changed Original file line number Diff line number Diff line change @@ -360,7 +360,7 @@ EXP_FUNC int STDCALL ssl_get_config(int offset);
360
360
* - 1 on success
361
361
* - 0 on failure
362
362
*/
363
- EXP_FUNC int STDCALL ssl_set_hostname (const SSL * ssl , const char * host_name );
363
+ EXP_FUNC int STDCALL ssl_set_hostname (SSL * ssl , const char * host_name );
364
364
365
365
/**
366
366
* @brief Display why the handshake failed.
Original file line number Diff line number Diff line change @@ -568,6 +568,8 @@ SSL *ssl_new(SSL_CTX *ssl_ctx, int client_fd)
568
568
ssl -> encrypt_ctx = malloc (sizeof (AES_CTX ));
569
569
ssl -> decrypt_ctx = malloc (sizeof (AES_CTX ));
570
570
571
+ ssl -> host_name = NULL ;
572
+
571
573
SSL_CTX_UNLOCK (ssl_ctx -> mutex );
572
574
return ssl ;
573
575
}
@@ -1852,14 +1854,24 @@ EXP_FUNC int STDCALL ssl_get_config(int offset)
1852
1854
/**
1853
1855
* Sets the SNI hostname
1854
1856
*/
1855
- EXP_FUNC int STDCALL ssl_set_hostname (const SSL * ssl , const char * host_name ) {
1856
- if (host_name == NULL || strlen (host_name ) == 0 || strlen (host_name ) > 255 ) {
1857
- return 0 ;
1858
- }
1857
+ EXP_FUNC int STDCALL ssl_set_hostname (SSL * ssl , const char * host_name ) {
1858
+ if (host_name == NULL || strlen (host_name ) == 0 || strlen (host_name ) > 255 ) {
1859
+ return 0 ;
1860
+ }
1861
+
1862
+ if (ssl -> host_name != NULL ) {
1863
+ free (ssl -> host_name );
1864
+ }
1865
+
1866
+ ssl -> host_name = (char * )malloc (strlen (host_name )+ 1 );
1867
+ if (ssl -> host_name == NULL ) {
1868
+ // most probably there was no memory available
1869
+ return 0 ;
1870
+ }
1859
1871
1860
- strncpy (( char * ) & ssl -> host_name , host_name , strlen ( host_name ) );
1872
+ strcpy ( ssl -> host_name , host_name );
1861
1873
1862
- return 1 ;
1874
+ return 1 ;
1863
1875
}
1864
1876
1865
1877
#ifdef CONFIG_SSL_CERT_VERIFICATION
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ struct _SSL
198
198
uint8_t read_sequence [8 ]; /* 64 bit sequence number */
199
199
uint8_t write_sequence [8 ]; /* 64 bit sequence number */
200
200
uint8_t hmac_header [SSL_RECORD_SIZE ]; /* rx hmac */
201
- const char host_name [ 255 ] ; /* Needed for the SNI support */
201
+ char * host_name ; /* Needed for the SNI support */
202
202
};
203
203
204
204
typedef struct _SSL SSL ;
Original file line number Diff line number Diff line change @@ -221,23 +221,23 @@ static int send_client_hello(SSL *ssl)
221
221
buf [offset ++ ] = 1 ; /* no compression */
222
222
buf [offset ++ ] = 0 ;
223
223
224
- if (ssl -> host_name [ 0 ] != 0 ) {
225
- unsigned int host_len = strnlen (( char * ) ssl -> host_name , 255 );
226
-
227
- buf [offset ++ ] = 0 ;
228
- buf [offset ++ ] = host_len + 9 ; /* extensions length */
229
-
230
- buf [offset ++ ] = 0 ;
231
- buf [offset ++ ] = 0 ; /* server_name(0) (65535) */
232
- buf [offset ++ ] = 0 ;
233
- buf [offset ++ ] = host_len + 5 ; /* server_name length */
234
- buf [offset ++ ] = 0 ;
235
- buf [offset ++ ] = host_len + 3 ; /* server_list length */
236
- buf [offset ++ ] = 0 ; /* host_name(0) (255) */
237
- buf [offset ++ ] = 0 ;
238
- buf [offset ++ ] = host_len ; /* host_name length */
239
- strncpy ((char * ) & buf [offset ], ssl -> host_name , host_len );
240
- offset += host_len ;
224
+ if (ssl -> host_name != NULL ) {
225
+ unsigned int host_len = strlen ( ssl -> host_name );
226
+
227
+ buf [offset ++ ] = 0 ;
228
+ buf [offset ++ ] = host_len + 9 ; /* extensions length */
229
+
230
+ buf [offset ++ ] = 0 ;
231
+ buf [offset ++ ] = 0 ; /* server_name(0) (65535) */
232
+ buf [offset ++ ] = 0 ;
233
+ buf [offset ++ ] = host_len + 5 ; /* server_name length */
234
+ buf [offset ++ ] = 0 ;
235
+ buf [offset ++ ] = host_len + 3 ; /* server_list length */
236
+ buf [offset ++ ] = 0 ; /* host_name(0) (255) */
237
+ buf [offset ++ ] = 0 ;
238
+ buf [offset ++ ] = host_len ; /* host_name length */
239
+ strncpy ((char * ) & buf [offset ], ssl -> host_name , host_len );
240
+ offset += host_len ;
241
241
}
242
242
243
243
buf [3 ] = offset - 4 ; /* handshake size */
You can’t perform that action at this time.
0 commit comments