[PATCH] libosmocore[master]: fix logging: also catch first out-of-bounds logging cat

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Dec 12 15:09:58 UTC 2016


Review at  https://gerrit.osmocom.org/1417

fix logging: also catch first out-of-bounds logging cat

In map_subsys(), fix the '>' condition to '>=' for array bounds checking.

Also make the bounds checking more strict: after both invocations of
subsys_lib2index(), re-check validity of the array index. If the final index is
still wrong, which should never happen, exit by assertion.

Change-Id: I7ca1a1d47724e40350f1c4dfebe90bad01c965f9
---
M src/logging.c
M tests/logging/logging_test.err
2 files changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/17/1417/1

diff --git a/src/logging.c b/src/logging.c
index 7102543..2a8bfdc 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -339,9 +339,11 @@
 	if (subsys < 0)
 		subsys = subsys_lib2index(subsys);
 
-	if (subsys > osmo_log_info->num_cat)
+	if (subsys < 0 || subsys >= osmo_log_info->num_cat)
 		subsys = subsys_lib2index(DLGLOBAL);
 
+	OSMO_ASSERT(!(subsys < 0 || subsys >= osmo_log_info->num_cat));
+
 	return subsys;
 }
 
diff --git a/tests/logging/logging_test.err b/tests/logging/logging_test.err
index cc21b32..273a852 100644
--- a/tests/logging/logging_test.err
+++ b/tests/logging/logging_test.err
@@ -3,3 +3,4 @@
 DRLL You should see this
 DLGLOBAL You should see this on DLGLOBAL (a)
 DLGLOBAL You should see this on DLGLOBAL (b)
+DLGLOBAL You should see this on DLGLOBAL (c)

-- 
To view, visit https://gerrit.osmocom.org/1417
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ca1a1d47724e40350f1c4dfebe90bad01c965f9
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list