From 19b19f05bd7e8a6c359b6bc36be91e3b75265881 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 19 Nov 2017 16:27:53 +0100 Subject: [PATCH] Correct range checks for network protocol parameters. Several checks were off by one, resulting in a segfault when only one parameter was missing. Also improve error messages, giving details about what is expected. --- src/Main/fg_io.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index 55eda9900..ca2385440 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -225,8 +225,9 @@ FGIO::parse_port_config( const string& config ) return NULL; } - if (tokens.size() < 3) { - SG_LOG( SG_IO, SG_ALERT, "Incompatible number of network arguments."); + if (tokens.size() < 4) { + SG_LOG( SG_IO, SG_ALERT, "Too few arguments for network protocol. At least 3 arguments required. " << + "Usage: --" << protocol << "=(file|socket|serial), (in|out|bi), hertz"); delete io; return NULL; } @@ -243,8 +244,9 @@ FGIO::parse_port_config( const string& config ) SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz ); if ( medium == "serial" ) { - if ( tokens.size() < 5) { - SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for serial communications."); + if ( tokens.size() < 6) { + SG_LOG( SG_IO, SG_ALERT, "Too few arguments for serial communications. " << + "Usage --" << protocol << "=serial, (in|out|bi), hertz, device, baudrate"); delete io; return NULL; } @@ -273,8 +275,9 @@ FGIO::parse_port_config( const string& config ) } } else if ( medium == "file" ) { // file name - if ( tokens.size() < 4) { - SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for file I/O."); + if ( tokens.size() < 5) { + SG_LOG( SG_IO, SG_ALERT, "Too few arguments for file I/O. " << + "Usage --" << protocol << "=file, (in|out), hertz, filename (,repeat)"); delete io; return NULL; } @@ -295,8 +298,9 @@ FGIO::parse_port_config( const string& config ) SGFile *ch = new SGFile( file, repeat ); io->set_io_channel( ch ); } else if ( medium == "socket" ) { - if ( tokens.size() < 6) { - SG_LOG( SG_IO, SG_ALERT, "Incompatible number of arguments for socket communications."); + if ( tokens.size() < 7) { + SG_LOG( SG_IO, SG_ALERT, "Too few arguments for socket communications. " << + "Usage --" << protocol << "=socket, (in|out|bi), hertz, hostname, port, (tcp|udp)"); delete io; return NULL; }