[PATCH] libosmocore[master]: fix logging: redirection to DLGLOBAL for invalid categories

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

fix logging: redirection to DLGLOBAL for invalid categories

For out-of-bounds logging categories, redirect to the proper DLGLOBAL array
index instead of returning -1.

Adjust test expectation which shows that the bugs tested for are fixed.

Note: there are separate bounds checking problems, left for another patch.

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


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/15/1415/1

diff --git a/src/logging.c b/src/logging.c
index 92852c9..7102543 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -328,13 +328,20 @@
 	target->output(target, level, buf);
 }
 
+/* Catch internal logging category indexes as well as out-of-bounds indexes.
+ * For internal categories, the ID is negative starting with -1; and internal
+ * logging categories are added behind the user categories. For out-of-bounds
+ * indexes, return the index of DLGLOBAL. The returned category index is
+ * guaranteed to exist in osmo_log_info, otherwise the program would abort,
+ * which should never happen unless even the DLGLOBAL category is missing. */
 static inline int map_subsys(int subsys)
 {
 	if (subsys < 0)
 		subsys = subsys_lib2index(subsys);
 
 	if (subsys > osmo_log_info->num_cat)
-		subsys = DLGLOBAL;
+		subsys = subsys_lib2index(DLGLOBAL);
+
 	return subsys;
 }
 
diff --git a/tests/logging/logging_test.err b/tests/logging/logging_test.err
index 4a350fa..cc21b32 100644
--- a/tests/logging/logging_test.err
+++ b/tests/logging/logging_test.err
@@ -1,3 +1,5 @@
 DRLL You should see this
 DCC You should see this
 DRLL You should see this
+DLGLOBAL You should see this on DLGLOBAL (a)
+DLGLOBAL You should see this on DLGLOBAL (b)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ea9a59e005a22e0305454291714fdb9531c346b
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