summaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-08-18 15:22:01 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-21 15:34:14 +0200
commit3463941c724966c30a827c39b70360fa4bbe0bd9 (patch)
treeae7be0fef5fd79bf67ab449b400f5966981af54b /openbsc/src
parent5d9b203db61b1840562b040411ca69a0fed9d80f (diff)
ctrl: Use strtol instead of atoi to detect conversion errors
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/libctrl/control_if.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c
index 98748d58..e76b4e5f 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -115,10 +115,30 @@ struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd)
return trap;
}
+static int get_num(vector vline, int i, long *num)
+{
+ char *token, *tmp;
+
+ if (i >= vector_active(vline))
+ return 0;
+ token = vector_slot(vline, i);
+
+ errno = 0;
+ if (token[0] == '\0')
+ return 0;
+
+ *num = strtol(token, &tmp, 10);
+ if (tmp[0] != '\0' || errno != 0)
+ return 0;
+
+ return 1;
+}
+
int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
{
char *token, *request;
- int num, i, j, ret, node;
+ long num;
+ int i, j, ret, node;
struct gsm_network *gsmnet = data;
struct gsm_network *net = NULL;
@@ -163,10 +183,9 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
if (!net)
goto err_missing;
i++;
- if (i >= vector_active(vline))
+ if (!get_num(vline, i, &num))
goto err_index;
- token = vector_slot(vline, i);
- num = atoi(token);
+
bts = gsm_bts_num(net, num);
if (!bts)
goto err_missing;
@@ -176,10 +195,9 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
if (!bts)
goto err_missing;
i++;
- if (i >= vector_active(vline))
+ if (!get_num(vline, i, &num))
goto err_index;
- token = vector_slot(vline, i);
- num = atoi(token);
+
trx = gsm_bts_trx_num(bts, num);
if (!trx)
goto err_missing;
@@ -189,10 +207,9 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data)
if (!trx)
goto err_missing;
i++;
- if (i >= vector_active(vline))
+ if (!get_num(vline, i, &num))
goto err_index;
- token = vector_slot(vline, i);
- num = atoi(token);
+
if ((num >= 0) && (num < TRX_NR_TS))
ts = &trx->ts[num];
if (!ts)