Minor optimizations (original by Peter Vaskovic, modified by Paul Bakker)
Move strlen out of for loop. Remove redundant null checks before free.
This commit is contained in:
parent
8ebfe084ab
commit
14b16c62e9
@ -370,10 +370,7 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
|
||||
|
||||
void pem_free( pem_context *ctx )
|
||||
{
|
||||
if( ctx->buf )
|
||||
polarssl_free( ctx->buf );
|
||||
|
||||
if( ctx->info )
|
||||
polarssl_free( ctx->info );
|
||||
|
||||
memset( ctx, 0, sizeof( pem_context ) );
|
||||
|
@ -321,7 +321,6 @@ void ssl_cache_free( ssl_cache_context *cache )
|
||||
ssl_session_free( &prv->session );
|
||||
|
||||
#if defined(POLARSSL_X509_CRT_PARSE_C)
|
||||
if( prv->peer_cert.p != NULL )
|
||||
polarssl_free( prv->peer_cert.p );
|
||||
#endif /* POLARSSL_X509_CRT_PARSE_C */
|
||||
|
||||
|
@ -691,7 +691,7 @@ static int ssl_parse_session_ticket_ext( ssl_context *ssl,
|
||||
static int ssl_parse_alpn_ext( ssl_context *ssl,
|
||||
unsigned char *buf, size_t len )
|
||||
{
|
||||
size_t list_len, cur_len;
|
||||
size_t list_len, cur_len, ours_len;
|
||||
const unsigned char *theirs, *start, *end;
|
||||
const char **ours;
|
||||
|
||||
@ -722,6 +722,7 @@ static int ssl_parse_alpn_ext( ssl_context *ssl,
|
||||
end = buf + len;
|
||||
for( ours = ssl->alpn_list; *ours != NULL; ours++ )
|
||||
{
|
||||
ours_len = strlen( *ours );
|
||||
for( theirs = start; theirs != end; theirs += cur_len )
|
||||
{
|
||||
/* If the list is well formed, we should get equality first */
|
||||
@ -734,7 +735,7 @@ static int ssl_parse_alpn_ext( ssl_context *ssl,
|
||||
if( cur_len == 0 )
|
||||
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
|
||||
|
||||
if( cur_len == strlen( *ours ) &&
|
||||
if( cur_len == ours_len &&
|
||||
memcmp( theirs, *ours, cur_len ) == 0 )
|
||||
{
|
||||
ssl->alpn_chosen = *ours;
|
||||
|
@ -1550,12 +1550,12 @@ static int x509_name_cmp( const void *s1, const void *s2, size_t len )
|
||||
static int x509_wildcard_verify( const char *cn, x509_buf *name )
|
||||
{
|
||||
size_t i;
|
||||
size_t cn_idx = 0;
|
||||
size_t cn_idx = 0, cn_len = strlen( cn );
|
||||
|
||||
if( name->len < 3 || name->p[0] != '*' || name->p[1] != '.' )
|
||||
return( 0 );
|
||||
|
||||
for( i = 0; i < strlen( cn ); ++i )
|
||||
for( i = 0; i < cn_len; ++i )
|
||||
{
|
||||
if( cn[i] == '.' )
|
||||
{
|
||||
@ -1567,7 +1567,7 @@ static int x509_wildcard_verify( const char *cn, x509_buf *name )
|
||||
if( cn_idx == 0 )
|
||||
return( 0 );
|
||||
|
||||
if( strlen( cn ) - cn_idx == name->len - 1 &&
|
||||
if( cn_len - cn_idx == name->len - 1 &&
|
||||
x509_name_cmp( name->p + 1, cn + cn_idx, name->len - 1 ) == 0 )
|
||||
{
|
||||
return( 1 );
|
||||
|
Loading…
Reference in New Issue
Block a user