Change in simtrace2[master]: minor: add checks on configurations and functions

2018-09-07 Thread Harald Welte
Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/10821 )

Change subject: minor: add checks on configurations and functions
..

minor: add checks on configurations and functions

these checks prevent out of bounds access and running
unset function pointers.

Change-Id: Ida889d40b898fc1ab8b885800431833570fdaafe
---
M firmware/apps/cardem/main.c
1 file changed, 17 insertions(+), 5 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/firmware/apps/cardem/main.c b/firmware/apps/cardem/main.c
index 600e4e9..0b5fbde 100644
--- a/firmware/apps/cardem/main.c
+++ b/firmware/apps/cardem/main.c
@@ -101,7 +101,11 @@
 void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum)
 {
TRACE_INFO_WP("cfgChanged%d ", cfgnum);
-   simtrace_config = cfgnum;
+   if (cfgnum < ARRAY_SIZE(config_func_ptrs)) {
+   simtrace_config = cfgnum;
+   } else {
+   TRACE_ERROR("trying to set out of bounds config %u\r\n", 
cfgnum);
+   }
 }

 void USART1_IrqHandler(void)
@@ -204,7 +208,9 @@
}

TRACE_INFO("calling init of config %u...\n\r", simtrace_config);
-   config_func_ptrs[simtrace_config].init();
+   if (config_func_ptrs[simtrace_config].init) {
+   config_func_ptrs[simtrace_config].init();
+   }
last_simtrace_config = simtrace_config;

TRACE_INFO("entering main loop...\n\r");
@@ -232,11 +238,17 @@
if (last_simtrace_config != simtrace_config) {
TRACE_INFO("USB config chg %u -> %u\n\r",
   last_simtrace_config, simtrace_config);
-   config_func_ptrs[last_simtrace_config].exit();
-   config_func_ptrs[simtrace_config].init();
+   if (config_func_ptrs[last_simtrace_config].exit) {
+   config_func_ptrs[last_simtrace_config].exit();
+   }
+   if (config_func_ptrs[simtrace_config].init) {
+   config_func_ptrs[simtrace_config].init();
+   }
last_simtrace_config = simtrace_config;
} else {
-   config_func_ptrs[simtrace_config].run();
+   if (config_func_ptrs[simtrace_config].run) {
+   config_func_ptrs[simtrace_config].run();
+   }
}
}
 }

--
To view, visit https://gerrit.osmocom.org/10821
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ida889d40b898fc1ab8b885800431833570fdaafe
Gerrit-Change-Number: 10821
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)


Change in simtrace2[master]: minor: add checks on configurations and functions

2018-09-07 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/10821 )

Change subject: minor: add checks on configurations and functions
..


Patch Set 1: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/10821
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ida889d40b898fc1ab8b885800431833570fdaafe
Gerrit-Change-Number: 10821
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Comment-Date: Fri, 07 Sep 2018 06:30:25 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes