mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-05-31 12:47:12 +00:00
Changed main buf to be allocated from heap in ssl_client2
This commit is contained in:
parent
8e0fe19a6a
commit
8e0e48199b
|
@ -935,7 +935,8 @@ int main( int argc, char *argv[] )
|
||||||
io_ctx_t io_ctx;
|
io_ctx_t io_ctx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned char buf[MAX_REQUEST_SIZE + 1];
|
unsigned char *buf = NULL;
|
||||||
|
unsigned int main_buf_len = 0;
|
||||||
|
|
||||||
#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];
|
||||||
|
@ -1521,6 +1522,13 @@ int main( int argc, char *argv[] )
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_buf_len = MAX_REQUEST_SIZE + 1;
|
||||||
|
buf = mbedtls_calloc( 1, MAX_REQUEST_SIZE + 1 );
|
||||||
|
if( buf == NULL ) {
|
||||||
|
mbedtls_printf( "buf allocation failed!\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/* Event-driven IO is incompatible with the above custom
|
/* Event-driven IO is incompatible with the above custom
|
||||||
* receive and send functions, as the polling builds on
|
* receive and send functions, as the polling builds on
|
||||||
* refers to the underlying net_context. */
|
* refers to the underlying net_context. */
|
||||||
|
@ -2449,7 +2457,7 @@ 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, main_buf_len - 1, GET_REQUEST,
|
||||||
opt.request_page );
|
opt.request_page );
|
||||||
tail_len = (int) strlen( GET_REQUEST_END );
|
tail_len = (int) strlen( GET_REQUEST_END );
|
||||||
|
|
||||||
|
@ -2461,7 +2469,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, main_buf_len - 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 */
|
||||||
|
@ -2577,8 +2585,8 @@ send_request:
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
len = sizeof( buf ) - 1;
|
len = main_buf_len - 1;
|
||||||
memset( buf, 0, sizeof( buf ) );
|
memset( buf, 0, main_buf_len );
|
||||||
ret = mbedtls_ssl_read( ssl, buf, len );
|
ret = mbedtls_ssl_read( ssl, buf, len );
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||||
|
@ -2639,8 +2647,8 @@ send_request:
|
||||||
}
|
}
|
||||||
else /* Not stream, so datagram */
|
else /* Not stream, so datagram */
|
||||||
{
|
{
|
||||||
len = sizeof( buf ) - 1;
|
len = main_buf_len - 1;
|
||||||
memset( buf, 0, sizeof( buf ) );
|
memset( buf, 0, main_buf_len );
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
@ -2994,6 +3002,7 @@ exit:
|
||||||
mbedtls_free( ssl );
|
mbedtls_free( ssl );
|
||||||
mbedtls_free( conf );
|
mbedtls_free( conf );
|
||||||
mbedtls_free( entropy );
|
mbedtls_free( entropy );
|
||||||
|
mbedtls_free( buf );
|
||||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||||
mbedtls_free( ctr_drbg );
|
mbedtls_free( ctr_drbg );
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue