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
This commit is contained in:
Neels Hofmeyr 2016-12-12 15:13:56 +01:00
parent 85b42c4618
commit 42240de04c
2 changed files with 10 additions and 1 deletions

View File

@ -328,13 +328,20 @@ err:
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;
}

View File

@ -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)