Change in libosmocore[master]: logging vty: write: check logging levels validity

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.org
Wed Sep 12 01:50:16 UTC 2018


Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/10887


Change subject: logging vty: write: check logging levels validity
......................................................................

logging vty: write: check logging levels validity

Change-Id: If683b1272ad2d5b402b91c52c496aa7975bc6315
---
M src/vty/logging_vty.c
1 file changed, 21 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/87/10887/1

diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index d0a9421..1f5cf2a 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -861,21 +861,35 @@
 		get_value_string(logging_print_file_args, tgt->print_filename2),
 		VTY_NEWLINE);
 
-	if (tgt->loglevel)
-		vty_out(vty, "  logging level all %s%s",
-			get_value_string(loglevel_strs_lower, tgt->loglevel),
-			VTY_NEWLINE);
+	if (tgt->loglevel) {
+		const char *level_str = get_value_string_or_null(loglevel_strs_lower, tgt->loglevel);
+		if (!level_str)
+			vty_out(vty, "%% Invalid log level %u for 'all'%s", tgt->loglevel, VTY_NEWLINE);
+		else
+			vty_out(vty, "  logging level all %s%s", level_str, VTY_NEWLINE);
+	}
 
 	for (i = 0; i < osmo_log_info->num_cat; i++) {
 		const struct log_category *cat = &tgt->categories[i];
+		const char *cat_name;
+		const char *level_str;
 
 		/* skip empty entries in the array */
 		if (!osmo_log_info->cat[i].name)
 			continue;
 
-		/* stupid old osmo logging API uses uppercase strings... */
-		vty_out(vty, "  logging level %s", osmo_str_tolower(osmo_log_info->cat[i].name+1));
-		vty_out(vty, " %s%s", get_value_string(loglevel_strs_lower, cat->loglevel), VTY_NEWLINE);
+		/* Note: cat_name references the static buffer returned by osmo_str_tolower(), will
+		 * become invalid after next osmo_str_tolower() invocation. */
+		cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1);
+
+		level_str = get_value_string_or_null(loglevel_strs_lower, cat->loglevel);
+		if (!level_str) {
+			vty_out(vty, "%% Invalid log level %u for %s%s", cat->loglevel, cat_name,
+				VTY_NEWLINE);
+			continue;
+		}
+
+		vty_out(vty, "  logging level %s %s%s", cat_name, level_str, VTY_NEWLINE);
 	}
 
 	return 1;

-- 
To view, visit https://gerrit.osmocom.org/10887
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If683b1272ad2d5b402b91c52c496aa7975bc6315
Gerrit-Change-Number: 10887
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180912/6ecaab82/attachment.htm>


More information about the gerrit-log mailing list