diff options
author | Harald Welte <laforge@gnumonks.org> | 2011-07-16 13:35:24 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-07-16 13:35:24 +0200 |
commit | 5b3c05d89a9465c891bcfebd8a58024d8d3e09a3 (patch) | |
tree | c0de4377c4c86d46453d4b75a61dc8ecd434dc15 /openbsc/src/utils | |
parent | 258c713343ff61bd633a09931cf9695bf460a607 (diff) |
bs11_config: fix array bounds problem by using value_string
Detected by Smatch:
/home/laforge/projects/git/openbsc/openbsc/src/utils/bs11_config.c +223 linkstate_name(5) error: buffer overflow 'bs11_link_state' 3 <= 3
/home/laforge/projects/git/openbsc/openbsc/src/utils/bs11_config.c +240 mbccu_load_name(5) error: buffer overflow 'mbccu_load' 6 <= 6
/home/laforge/projects/git/openbsc/openbsc/src/utils/bs11_config.c +905 main(34) info: ignoring unreachable code.
Diffstat (limited to 'openbsc/src/utils')
-rw-r--r-- | openbsc/src/utils/bs11_config.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/openbsc/src/utils/bs11_config.c b/openbsc/src/utils/bs11_config.c index 41acd6920..ef0107292 100644 --- a/openbsc/src/utils/bs11_config.c +++ b/openbsc/src/utils/bs11_config.c @@ -35,6 +35,7 @@ #include <openbsc/gsm_data.h> #include <openbsc/abis_nm.h> #include <osmocom/core/msgb.h> +#include <osmocom/core/utils.h> #include <osmocom/gsm/tlv.h> #include <openbsc/debug.h> #include <osmocom/core/select.h> @@ -209,35 +210,31 @@ static int swload_cbfn(unsigned int hook, unsigned int event, struct msgb *msg, return 0; } -static const char *bs11_link_state[] = { - [0x00] = "Down", - [0x01] = "Up", - [0x02] = "Restoring", +static const struct value_string bs11_linkst_names[] = { + { 0, "Down" }, + { 1, "Up" }, + { 2, "Restoring" }, + { 0, NULL } }; static const char *linkstate_name(uint8_t linkstate) { - if (linkstate > ARRAY_SIZE(bs11_link_state)) - return "Unknown"; - - return bs11_link_state[linkstate]; + return get_value_string(bs11_linkst_names, linkstate); } -static const char *mbccu_load[] = { - [0] = "No Load", - [1] = "Load BTSCAC", - [2] = "Load BTSDRX", - [3] = "Load BTSBBX", - [4] = "Load BTSARC", - [5] = "Load", +static const struct value_string mbccu_load_names[] = { + { 0, "No Load" }, + { 1, "Load BTSCAC" }, + { 2, "Load BTSDRX" }, + { 3, "Load BTSBBX" }, + { 4, "Load BTSARC" }, + { 5, "Load" }, + { 0, NULL } }; static const char *mbccu_load_name(uint8_t linkstate) { - if (linkstate > ARRAY_SIZE(mbccu_load)) - return "Unknown"; - - return mbccu_load[linkstate]; + return get_value_string(mbccu_load_names, linkstate); } static const char *bts_phase_name(uint8_t phase) @@ -899,7 +896,8 @@ int main(int argc, char **argv) status_timer.cb = status_timer_cb; while (1) { - osmo_select_main(0); + if (osmo_select_main(0) < 0) + break; } abis_nm_bs11_factory_logon(g_bts, 0); |