[PATCH] logging.c: log_parse_category_mask(), skip log category name right away if name is NULL to prevent passing a NULL ptr to strlen

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/OpenBSC@lists.osmocom.org/.

Nico Golde nico at ngolde.de
Fri Sep 21 15:44:58 UTC 2012


---
 src/logging.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/logging.c b/src/logging.c
index 0816570..f368bea 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -167,6 +167,7 @@ void log_parse_category_mask(struct log_target* target, const char *_mask)
 	int i = 0;
 	char *mask = strdup(_mask);
 	char *category_token = NULL;
+	size_t length, cat_length;
 
 	/* Disable everything to enable it afterwards */
 	for (i = 0; i < osmo_log_info->num_cat; ++i)
@@ -176,16 +177,17 @@ void log_parse_category_mask(struct log_target* target, const char *_mask)
 	do {
 		for (i = 0; i < osmo_log_info->num_cat; ++i) {
 			char* colon = strstr(category_token, ",");
-			int length = strlen(category_token);
-			int cat_length = strlen(osmo_log_info->cat[i].name);
+
+			if (!osmo_log_info->cat[i].name)
+				continue;
+
+			length = strlen(category_token);
+			cat_length = strlen(osmo_log_info->cat[i].name);
 
 			/* Use longest length not to match subocurrences. */
 			if (cat_length > length)
 				length = cat_length;
 
-			if (!osmo_log_info->cat[i].name)
-				continue;
-
 			if (colon)
 			    length = colon - category_token;
 
-- 
1.7.10.4


--sdtB3X0nJg68CQEu--




More information about the OpenBSC mailing list