Commit Graph

14 Commits

Author SHA1 Message Date
Neels Hofmeyr 886d6fdec6 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
2016-12-12 16:56:54 +01:00
Neels Hofmeyr a4842afc83 show bug in logging: log_set_category_filter on DL* categories
Add a check to logging_test.c to show a bug: passing an internal DL* category
constant to log_set_category_filter() results in a negative array index and
undefined behavior. A sanitize build should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: Ie2da77c642a84cafc0f528985930697ec167183b
2016-12-12 16:56:54 +01:00
Neels Hofmeyr 748022694c 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
2016-12-12 16:56:50 +01:00
Neels Hofmeyr d1a145e5e7 show bug in logging: out-of-bounds check should end with user categories
In the background osmo_log_info array, the user's logging categories are
enhanced by the library internal ones. So far logging category range checking
only checked for the larger array bounds, although passing a logging category
>= num_cat_user is already semantically unknown and should redirect to
DLGLOBAL.

Add a check to logging_test.c to show that this isn't happening. Instead of
DLGLOBAL, a logging category that happens to be at that index is queried.

The bug is confirmed by logging_test.err only showing "(e)" and not "(d)":
"(e)" is shown because the first category after the user ones happens to be
DLGLOBAL. "(d)" is omitted since it hits a category that's not on debug level.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: I397278714018ee9a0ae5101515f31ddddf79c2ec
2016-12-12 16:09:14 +01:00
Neels Hofmeyr ca13574ba4 fix logging: also catch first out-of-bounds logging cat
In map_subsys(), fix the '>' condition to '>=' for array bounds checking.

Also make the bounds checking more strict: after both invocations of
subsys_lib2index(), re-check validity of the array index. If the final index is
still wrong, which should never happen, exit by assertion.

Change-Id: I7ca1a1d47724e40350f1c4dfebe90bad01c965f9
2016-12-12 15:48:08 +01:00
Neels Hofmeyr a280b82f8e show bug in logging: erratic redirection to DLGLOBAL for first invalid category
Add a check to logging_test.c to show a bug: when a logging category value that
is the first out-of-bounds value is passed to the logging system, the internal
map_subsys() fails to redirect to DLGLOBAL due to a flawed conditional. This
results in a too large array index and undefined behavior. A sanitize build
should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: I12bf38b6c1f85e2d7bf5a15f942dfe0beed41eba
2016-12-12 15:47:51 +01:00
Neels Hofmeyr 42240de04c 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
2016-12-12 15:47:37 +01:00
Neels Hofmeyr 85b42c4618 show bug in logging: erratic redirection to DLGLOBAL for invalid categories
Add a check to logging_test.c to show a bug: when a logging category value that
is out-of-bounds is passed to the logging system, the internal map_subsys()
function should remap that to DLGLOBAL. But in fact DLGLOBAL is -1 and the
function fails to map this to a proper positive array index, directly returning
-1 instead. This results in a negative array index and undefined behavior. A
sanitize build should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Note: osmo_log_info->num_cat + 0 is also out-of-bounds, but there is a separate
bug there, so leaving this for another patch.

Change-Id: I161b6550fa204a872bad1abefee1a6155393fafd
2016-12-12 15:47:32 +01:00
Neels Hofmeyr 9adf32fb60 logging test: cosmetic: print target and don't print color
Prepares for upcoming modifications of the logging test to show and fix bugs in
the logging system.

Change-Id: I9461b987adf85d87469a6af55de5f1aa478f6ebb
2016-12-12 14:24:39 +01:00
Holger Hans Peter Freyther 79599acd66 logging: Move the filter check up as well
There doesn't seem to be a reason not to check the filter. Update
and extend the test. Currently the filter function will be called
once for the log check and once for the output of it.
2016-02-29 14:30:14 +01:00
Jacob Erlbeck 64e0eb56fd log/test: Extend test case for log_check_level
This commit adds OSMO_ASSERTs for mandatory conditions related to
log_check_level, and fprintfs for optional conditions, since it is
always safe for log_check_level to return != 0.

Sponsored-by: On-Waves ehf
2016-02-29 14:30:14 +01:00
Holger Hans Peter Freyther b7d0f4686b logging: Copy the filter_fn and fix the IMSI filter in OpenBSC
The filter_fn has not been copied into the new structure breaking
the imsi and other filters in OpenBSC. Looking at the code we should
also introduce a callback for the reset of the context so we could
use subscr_get/subscr_put on the subscriber structure.
2013-12-29 19:38:01 +01:00
Holger Hans Peter Freyther 779d2f42a4 logging: Modify the testcase to excercise Nico's fix 2012-09-27 16:31:29 +02:00
Holger Hans Peter Freyther 4b54cab476 logging: Move the logging test from OpenBSC into libosmocore
Add a testcase for the logging facility. The test is coming from
the OpenBSC code.
2012-09-27 16:29:54 +02:00