diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index fa5114b..a9ab798 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -73,7 +73,7 @@ int main( int argc, char *argv[] ) } } - char *ip; + char *ip, *desired_port; int port; if ( argc - optind != 2 ) { @@ -82,7 +82,24 @@ int main( int argc, char *argv[] ) } ip = argv[ optind ]; - port = myatoi( argv[ optind + 1 ] ); + desired_port = argv[ optind + 1 ]; + + /* Sanity-check arguments */ + if ( ip + && ( strspn( ip, "0123456789." ) != strlen( ip ) ) ) { + fprintf( stderr, "%s: Bad IP address (%s)\n\n", argv[ 0 ], ip ); + usage( argv[ 0 ] ); + exit( 1 ); + } + + if ( desired_port + && ( strspn( desired_port, "0123456789" ) != strlen( desired_port ) ) ) { + fprintf( stderr, "%s: Bad UDP port (%s)\n\n", argv[ 0 ], desired_port ); + usage( argv[ 0 ] ); + exit( 1 ); + } + + port = myatoi( desired_port ); /* Read key from environment */ char *env_key = getenv( "MOSH_KEY" );