fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30729 ) Change subject: trxcon: use strtoul() instead of atoi(), detect errors ...................................................................... trxcon: use strtoul() instead of atoi(), detect errors Change-Id: I18ec88f1ee30c58d088fe65650d0257b262c1fee --- M src/host/trxcon/src/trxcon_main.c 1 file changed, 18 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve Hoernchen: Looks good to me, but someone else must approve fixeria: Looks good to me, approved diff --git a/src/host/trxcon/src/trxcon_main.c b/src/host/trxcon/src/trxcon_main.c index 95e5549..742246e 100644 --- a/src/host/trxcon/src/trxcon_main.c +++ b/src/host/trxcon/src/trxcon_main.c @@ -188,6 +188,7 @@ static void handle_options(int argc, char **argv) { while (1) { + char *endptr = NULL; int option_index = 0, c; static struct option long_options[] = { {"help", 0, 0, 'h'}, @@ -211,6 +212,8 @@ if (c == -1) break; + errno = 0; + switch (c) { case 'h': print_usage(argv[0]); @@ -227,10 +230,18 @@ app_data.trx_remote_ip = optarg; break; case 'p': - app_data.trx_base_port = atoi(optarg); + app_data.trx_base_port = strtoul(optarg, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "Failed to parse -p/--trx-port=%s\n", optarg); + exit(EXIT_FAILURE); + } break; case 'f': - app_data.trx_fn_advance = atoi(optarg); + app_data.trx_fn_advance = strtoul(optarg, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "Failed to parse -f/--trx-advance=%s\n", optarg); + exit(EXIT_FAILURE); + } break; case 's': app_data.bind_socket = optarg; @@ -239,7 +250,11 @@ app_data.gsmtap_ip = optarg; break; case 'C': - app_data.max_clients = atoi(optarg); + app_data.max_clients = strtoul(optarg, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "Failed to parse -C/--max-clients=%s\n", optarg); + exit(EXIT_FAILURE); + } break; case 'D': app_data.daemonize = 1; -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30729 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I18ec88f1ee30c58d088fe65650d0257b262c1fee Gerrit-Change-Number: 30729 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: Hoernchen <ewild@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> Gerrit-Reviewer: pespin <pespin@sysmocom.de> Gerrit-MessageType: merged