aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2018-03-16 17:52:14 +0100
committerHarald Welte <laforge@gnumonks.org>2018-03-16 18:54:44 +0000
commitb1b8b624a6325bfc1c359be4ff8fd49de820c7fe (patch)
tree0b1c6b6f0a5ca61dd5603af6fc6a82d97834e369
parent8972f3fe4c5c26ef407779bec79dbd1c865b067d (diff)
ipaccess-config: Check cmdlie arg unit-id format
Print a clear error when the format in not correct. I was in the situation several times in which I was passing "123" instead of "123/0/0", and spent a while seeing what was wrong. Change-Id: I70906939b3320473c56a87929c4886aac9d7d064
-rw-r--r--src/ipaccess/ipaccess-config.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ipaccess/ipaccess-config.c b/src/ipaccess/ipaccess-config.c
index b83846d32..7b9bd0284 100644
--- a/src/ipaccess/ipaccess-config.c
+++ b/src/ipaccess/ipaccess-config.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <getopt.h>
#include <errno.h>
+#include <ctype.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
@@ -782,6 +783,41 @@ static void analyze_firmware(const char *filename)
talloc_free(tall_firm_ctx);
}
+static bool check_unitid_fmt(const char* unit_id)
+{
+ const char *p = unit_id;
+ bool must_digit = true;
+ uint8_t remain_slash = 2;
+
+ if (strlen(unit_id) < 5)
+ goto wrong_fmt;
+
+ while (*p != '\0') {
+ if (*p != '/' && !isdigit(*p))
+ goto wrong_fmt;
+ if (*p == '/' && must_digit)
+ goto wrong_fmt;
+ if (*p == '/') {
+ must_digit = true;
+ remain_slash--;
+ if (remain_slash < 0)
+ goto wrong_fmt;
+ } else {
+ must_digit = false;
+ }
+ p++;
+ }
+
+ if (*(p-1) == '/')
+ goto wrong_fmt;
+
+ return true;
+
+wrong_fmt:
+ fprintf(stderr, "ERROR: unit-id wrong format. Must be '\\d+/\\d+/\\d+'\n");
+ return false;
+}
+
static void print_usage(void)
{
printf("Usage: ipaccess-config IP_OF_BTS\n");
@@ -904,6 +940,8 @@ int main(int argc, char **argv)
switch (c) {
case 'u':
+ if (!check_unitid_fmt(optarg))
+ exit(2);
unit_id = optarg;
break;
case 'o':