mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-08 10:25:37 +00:00
Allow requests of size larger than 16384 in ssl_client2
This commit is contained in:
parent
fe7fd6e8dc
commit
1a662eb928
|
@ -60,6 +60,9 @@ int main( void )
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX_REQUEST_SIZE 20000
|
||||||
|
#define MAX_REQUEST_SIZE_STR "20000"
|
||||||
|
|
||||||
#define DFL_SERVER_NAME "localhost"
|
#define DFL_SERVER_NAME "localhost"
|
||||||
#define DFL_SERVER_ADDR NULL
|
#define DFL_SERVER_ADDR NULL
|
||||||
#define DFL_SERVER_PORT "4433"
|
#define DFL_SERVER_PORT "4433"
|
||||||
|
@ -231,8 +234,8 @@ int main( void )
|
||||||
" server_addr=%%s default: given by name\n" \
|
" server_addr=%%s default: given by name\n" \
|
||||||
" server_port=%%d default: 4433\n" \
|
" server_port=%%d default: 4433\n" \
|
||||||
" request_page=%%s default: \".\"\n" \
|
" request_page=%%s default: \".\"\n" \
|
||||||
" request_size=%%d default: about 34 (basic request)\n" \
|
" request_size=%%d default: about 34 (basic request)\n" \
|
||||||
" (minimum: 0, max: 16384)\n" \
|
" (minimum: 0, max: " MAX_REQUEST_SIZE_STR " )\n" \
|
||||||
" debug_level=%%d default: 0 (disabled)\n" \
|
" debug_level=%%d default: 0 (disabled)\n" \
|
||||||
" nbio=%%d default: 0 (blocking I/O)\n" \
|
" nbio=%%d default: 0 (blocking I/O)\n" \
|
||||||
" options: 1 (non-blocking), 2 (added delays)\n" \
|
" options: 1 (non-blocking), 2 (added delays)\n" \
|
||||||
|
@ -424,7 +427,9 @@ int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
int ret = 0, len, tail_len, i, written, frags, retry_left;
|
||||||
mbedtls_net_context server_fd;
|
mbedtls_net_context server_fd;
|
||||||
unsigned char buf[MBEDTLS_SSL_MAX_CONTENT_LEN + 1];
|
|
||||||
|
unsigned char buf[MAX_REQUEST_SIZE + 1];
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||||
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
|
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
|
||||||
size_t psk_len = 0;
|
size_t psk_len = 0;
|
||||||
|
@ -588,7 +593,8 @@ int main( int argc, char *argv[] )
|
||||||
else if( strcmp( p, "request_size" ) == 0 )
|
else if( strcmp( p, "request_size" ) == 0 )
|
||||||
{
|
{
|
||||||
opt.request_size = atoi( q );
|
opt.request_size = atoi( q );
|
||||||
if( opt.request_size < 0 || opt.request_size > MBEDTLS_SSL_MAX_CONTENT_LEN )
|
if( opt.request_size < 0 ||
|
||||||
|
opt.request_size > MAX_REQUEST_SIZE )
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
else if( strcmp( p, "ca_file" ) == 0 )
|
else if( strcmp( p, "ca_file" ) == 0 )
|
||||||
|
@ -1465,8 +1471,8 @@ send_request:
|
||||||
mbedtls_printf( " > Write to server:" );
|
mbedtls_printf( " > Write to server:" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
len = mbedtls_snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
|
len = mbedtls_snprintf( (char *) buf, sizeof( buf ) - 1, GET_REQUEST,
|
||||||
opt.request_page );
|
opt.request_page );
|
||||||
tail_len = (int) strlen( GET_REQUEST_END );
|
tail_len = (int) strlen( GET_REQUEST_END );
|
||||||
|
|
||||||
/* Add padding to GET request to reach opt.request_size in length */
|
/* Add padding to GET request to reach opt.request_size in length */
|
||||||
|
@ -1477,7 +1483,7 @@ send_request:
|
||||||
len += opt.request_size - len - tail_len;
|
len += opt.request_size - len - tail_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy( (char *) buf + len, GET_REQUEST_END, sizeof(buf) - len - 1 );
|
strncpy( (char *) buf + len, GET_REQUEST_END, sizeof( buf ) - len - 1 );
|
||||||
len += tail_len;
|
len += tail_len;
|
||||||
|
|
||||||
/* Truncate if request size is smaller than the "natural" size */
|
/* Truncate if request size is smaller than the "natural" size */
|
||||||
|
@ -1521,6 +1527,12 @@ send_request:
|
||||||
|
|
||||||
frags = 1;
|
frags = 1;
|
||||||
written = ret;
|
written = ret;
|
||||||
|
|
||||||
|
if( written < len )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " warning\n ! request didn't fit into single datagram and "
|
||||||
|
"was truncated to size %u", (unsigned) written );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[written] = '\0';
|
buf[written] = '\0';
|
||||||
|
|
Loading…
Reference in a new issue