Handle crypto exceptions in UI without dying

This commit is contained in:
Keith Winstein
2012-02-02 16:48:35 -05:00
parent f6de17eb71
commit 3edccf1f2e
3 changed files with 15 additions and 9 deletions
+3 -3
View File
@@ -29,7 +29,7 @@ Packet::Packet( string coded_packet, Session *session )
direction = (message.nonce.val() & DIRECTION_MASK) ? TO_CLIENT : TO_SERVER;
seq = message.nonce.val() & SEQUENCE_MASK;
assert( message.text.size() >= 2 * sizeof( uint16_t ) );
dos_assert( message.text.size() >= 2 * sizeof( uint16_t ) );
uint16_t *data = (uint16_t *)message.text.data();
timestamp = be16toh( data[ 0 ] );
@@ -220,13 +220,13 @@ string Connection::recv( void )
}
}
/* server auto-adjusts to client */
if ( server ) {
/* auto-adjust to remote host */
attached = true;
if ( (remote_addr.sin_addr.s_addr != packet_remote_addr.sin_addr.s_addr)
|| (remote_addr.sin_port != packet_remote_addr.sin_port) ) {
remote_addr = packet_remote_addr;
if ( server ) {
fprintf( stderr, "Server now attached to client at %s:%d\n",
inet_ntoa( remote_addr.sin_addr ),
ntohs( remote_addr.sin_port ) );
+3 -1
View File
@@ -294,8 +294,10 @@ void serve( int host_fd )
network.tick();
} catch ( Network::NetworkException e ) {
fprintf( stderr, "%s: %s\r\n", e.function.c_str(), strerror( e.the_errno ) );
fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) );
sleep( 1 );
} catch ( Crypto::CryptoException e ) {
fprintf( stderr, "Crypto exception: %s\n", e.text.c_str() );
}
}
}
+5 -1
View File
@@ -364,7 +364,7 @@ void STMClient::main( void )
} catch ( Network::NetworkException e ) {
if ( !network->shutdown_in_progress() ) {
wchar_t tmp[ 128 ];
swprintf( tmp, 128, L"%s: %s\r\n", e.function.c_str(), strerror( e.the_errno ) );
swprintf( tmp, 128, L"%s: %s", e.function.c_str(), strerror( e.the_errno ) );
overlays.get_notification_engine().set_notification_string( wstring( tmp ) );
}
@@ -372,6 +372,10 @@ void STMClient::main( void )
req.tv_sec = 0;
req.tv_nsec = 200000000; /* 0.2 sec */
nanosleep( &req, NULL );
} catch ( Crypto::CryptoException e ) {
wchar_t tmp[ 128 ];
swprintf( tmp, 128, L"Crypto exception: %s", e.text.c_str() );
overlays.get_notification_engine().set_notification_string( wstring( tmp ) );
}
}
}