From 5b3c05d89a9465c891bcfebd8a58024d8d3e09a3 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 16 Jul 2011 13:35:24 +0200 Subject: 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. --- openbsc/src/utils/bs11_config.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'openbsc/src/utils') 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 #include #include +#include #include #include #include @@ -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); -- cgit v1.2.3