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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Kévin Redon gerrit-no-reply at lists.osmocom.org
Thu Sep 6 21:19:46 UTC 2018


Kévin Redon has uploaded this change for review. ( 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(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/21/10821/1

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: newchange
Gerrit-Change-Id: Ida889d40b898fc1ab8b885800431833570fdaafe
Gerrit-Change-Number: 10821
Gerrit-PatchSet: 1
Gerrit-Owner: Kévin Redon <kredon at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180906/83109aac/attachment.htm>


More information about the gerrit-log mailing list