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.orgHello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/1419
to look at the new patch set (#3).
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.
While at it, also assert that we never have more than INT_MAX categories listed.
Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
---
M src/logging.c
M tests/logging/logging_test.err
2 files changed, 9 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/19/1419/3
diff --git a/src/logging.c b/src/logging.c
index 2a8bfdc..338eddc 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#include <limits.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
@@ -336,6 +337,13 @@
* which should never happen unless even the DLGLOBAL category is missing. */
static inline int map_subsys(int subsys)
{
+ /* comparing signed and unsigned integers here, let's make sure: */
+ OSMO_ASSERT(osmo_log_info->num_cat <= INT_MAX);
+ OSMO_ASSERT(osmo_log_info->num_cat_user <= INT_MAX);
+
+ 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: newpatchset
Gerrit-Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder