[MERGED] libosmocore[master]: fix logging: out-of-bounds check should end with user catego...

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

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Dec 13 14:56:28 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: fix logging: out-of-bounds check should end with user categories
......................................................................


fix logging: out-of-bounds check should end with user categories

To check category bounds, rather use num_cat_user, to redirect all semantically
unknown categories to DLGLOBAL.

Adjust logging_test expectations accordingly: "(d)" is now also shown.

Note: subsys is and needs to be signed, while num_cat* are unsigned. Thus for a
negative subsys, 'subsys >= num_cat_user' practically always yields true. Pay
close attention to signedness and check upper bound only for positive values.

Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
---
M src/logging.c
M tests/logging/logging_test.err
2 files changed, 6 insertions(+), 0 deletions(-)

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



diff --git a/src/logging.c b/src/logging.c
index 2a8bfdc..d32ca43 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -336,6 +336,11 @@
  * which should never happen unless even the DLGLOBAL category is missing. */
 static inline int map_subsys(int subsys)
 {
+	/* Note: comparing signed and unsigned integers */
+
+	if (subsys > 0 && ((unsigned int)subsys) >= osmo_log_info->num_cat_user)
+		subsys = DLGLOBAL;
+
 	if (subsys < 0)
 		subsys = subsys_lib2index(subsys);
 
diff --git a/tests/logging/logging_test.err b/tests/logging/logging_test.err
index f4e9c1f..4527d83 100644
--- a/tests/logging/logging_test.err
+++ b/tests/logging/logging_test.err
@@ -4,4 +4,5 @@
 DLGLOBAL You should see this on DLGLOBAL (a)
 DLGLOBAL You should see this on DLGLOBAL (b)
 DLGLOBAL You should see this on DLGLOBAL (c)
+DLGLOBAL You should see this on DLGLOBAL (d)
 DLGLOBAL You should see this on DLGLOBAL (e)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list