Proper initialization and checks for rare cases

This commit is contained in:
Paul Bakker 2014-07-09 14:58:11 +02:00
parent 1d073c59ad
commit a16e7f24f0
7 changed files with 16 additions and 3 deletions

View file

@ -113,6 +113,8 @@ int net_connect( int *fd, const char *host, int port )
struct sockaddr_in server_addr;
struct hostent *server_host;
memset( &server_addr, 0, sizeof( server_addr ) );
#if defined(_WIN32) || defined(_WIN32_WCE)
WSADATA wsaData;
@ -158,6 +160,8 @@ int net_bind( int *fd, const char *bind_ip, int port )
int n, c[4];
struct sockaddr_in server_addr;
memset( &server_addr, 0, sizeof( server_addr ) );
#if defined(_WIN32) || defined(_WIN32_WCE)
WSADATA wsaData;

View file

@ -502,7 +502,11 @@ int main( int argc, char *argv[] )
/*
* Write the final block of data
*/
cipher_finish( &cipher_ctx, output, &olen );
if( cipher_finish( &cipher_ctx, output, &olen ) != 0 )
{
fprintf( stderr, "cipher_finish() returned error\n" );
goto exit;
}
if( fwrite( output, 1, olen, fout ) != olen )
{

View file

@ -97,6 +97,9 @@ void write_public_key( rsa_context *rsa, const char *output_file )
c = base_buf;
f = fopen( output_file, "w" );
if( f == NULL )
return;
fprintf(f, "-----BEGIN PUBLIC KEY-----\n");
while (olen)
{

View file

@ -72,7 +72,7 @@ int main( int argc, char *argv[] )
#else
int main( int argc, char *argv[] )
{
int ret, len, server_fd;
int ret, len, server_fd = -1;
unsigned char buf[1024];
const char *pers = "ssl_client1";

View file

@ -97,7 +97,7 @@ int main( int argc, char *argv[] )
{
int ret, len, cnt = 0, pid;
int listen_fd;
int client_fd;
int client_fd = -1;
unsigned char buf[1024];
const char *pers = "ssl_fork_server";

View file

@ -373,6 +373,7 @@ int main( int argc, char *argv[] )
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &clicert, 0, sizeof( x509_cert ) );
memset( &rsa, 0, sizeof( rsa_context ) );
memset( &ssl, 0, sizeof( ssl_context ) );
if( argc == 0 )
{

View file

@ -259,6 +259,7 @@ int main( int argc, char *argv[] )
memset( &cacert, 0, sizeof( x509_cert ) );
memset( &srvcert, 0, sizeof( x509_cert ) );
memset( &rsa, 0, sizeof( rsa_context ) );
memset( &ssl, 0, sizeof( ssl_context ) );
#if defined(POLARSSL_SSL_CACHE_C)
ssl_cache_init( &cache );
#endif