[PATCH] libosmocore[master]: fix logging: log_set_category_filter() for internal DL* logg...

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:59 UTC 2016


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

fix logging: log_set_category_filter() for internal DL* logging cats

In log_set_category_filter(), passing a negative index lead to memory
corruption. Particularly dangerous since the internal logging categories have
negative values.

Fix: apply map_subsys() to interpret negative values as internal logging
categories.

As a side effect, out-of-bounds logging categories will be mapped to DLGLOBAL
instead of being dropped.

Fix the expectations in logging_test to match the fixed bug.

While at it also guard against a NULL logging target.

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


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/21/1421/1

diff --git a/src/logging.c b/src/logging.c
index 35815ae..1476551 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -572,8 +572,9 @@
 void log_set_category_filter(struct log_target *target, int category,
 			       int enable, int level)
 {
-	if (category >= osmo_log_info->num_cat)
+	if (!target)
 		return;
+	category = map_subsys(category);
 	target->categories[category].enabled = !!enable;
 	target->categories[category].loglevel = level;
 }
diff --git a/tests/logging/logging_test.err b/tests/logging/logging_test.err
index 4527d83..17b3cad 100644
--- a/tests/logging/logging_test.err
+++ b/tests/logging/logging_test.err
@@ -6,3 +6,4 @@
 DLGLOBAL You should see this on DLGLOBAL (c)
 DLGLOBAL You should see this on DLGLOBAL (d)
 DLGLOBAL You should see this on DLGLOBAL (e)
+DLGLOBAL You should see this (DLGLOBAL on DEBUG)

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

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