From 65110d2d99282a566b1d0e621783259bab909dce Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 21 Nov 2018 10:18:03 +0700 Subject: mobile: abort in case of argv handling errors The process should be aborted if a non-existing command line option or an incorrect parameter value is passed. Change-Id: Ib656ad12f12429ed15dc2a1554901ffa51148ff6 --- src/host/layer23/src/mobile/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/host/layer23/src') diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c index 115ac419..e015c301 100644 --- a/src/host/layer23/src/mobile/main.c +++ b/src/host/layer23/src/mobile/main.c @@ -99,7 +99,7 @@ static void print_help() "offer socket\n"); } -static void handle_options(int argc, char **argv) +static int handle_options(int argc, char **argv) { while (1) { int option_index = 0, c; @@ -148,9 +148,12 @@ static void handle_options(int argc, char **argv) use_mncc_sock = 1; break; default: - break; + /* Unknown parameter passed */ + return -EINVAL; } } + + return 0; } void sighandler(int sigset) @@ -218,7 +221,11 @@ int main(int argc, char **argv) /* Init default stderr logging */ osmo_init_logging2(l23_ctx, &log_info); - handle_options(argc, argv); + rc = handle_options(argc, argv); + if (rc) { /* Abort in case of parsing errors */ + fprintf(stderr, "Error in command line options. Exiting.\n"); + return 1; + } if (gsmtap_ip) { gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1); -- cgit v1.2.3