aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-12-12 16:00:24 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-12-12 16:56:50 +0100
commit748022694c57ce7b9412469b8190c7d232818a69 (patch)
tree91a3f6354f76017b692216287957b0ed6b4fd43c
parentd1a145e5e782d07140422b85da9f55dd4b35a206 (diff)
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
-rw-r--r--src/logging.c5
-rw-r--r--tests/logging/logging_test.err1
2 files changed, 6 insertions, 0 deletions
diff --git a/src/logging.c b/src/logging.c
index 2a8bfdc8..d32ca43a 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -336,6 +336,11 @@ err:
* 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 f4e9c1f4..4527d835 100644
--- a/tests/logging/logging_test.err
+++ b/tests/logging/logging_test.err
@@ -4,4 +4,5 @@ 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)
+DLGLOBAL You should see this on DLGLOBAL (d)
DLGLOBAL You should see this on DLGLOBAL (e)