aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-10-01 15:51:18 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-10-01 15:58:20 +0200
commitea6f519ff84c31acd2689e92adb4dc1688dd9a7a (patch)
treecf8b858f036e80361634d7979a160c1f67de7533 /src/vty
parent40f35212c71e8926b0dfe7463af959f00c56cd82 (diff)
vty logging: fix crash when missing 'logging enable'
We must explicitly check the return value of osmo_log_vty2tgt(), or may run into a segfault. I wasn't aware of this and introduced numerous such cases in I36f17c131cc70ce5a1aef62fd9693097de230cd4. Reproduce: on the VTY, do not issue 'logging enable', invoke 'logging level force-all LEVEL' first. Show in logging_vty_test.vty that this situation is now again amended by telling the user that logging was not enabled. Related: OS#3611 Change-Id: Id11702d1801d6654ca5e5a51b597a0d802e2e8dd
Diffstat (limited to 'src/vty')
-rw-r--r--src/vty/logging_vty.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 31edb528..f3e1419c 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -364,6 +364,10 @@ DEFUN(logging_level_set_all, logging_level_set_all_cmd,
struct log_target *tgt = osmo_log_vty2tgt(vty);
int level = log_parse_level(argv[0]);
int i;
+
+ if (!tgt)
+ return CMD_WARNING;
+
for (i = 0; i < osmo_log_info->num_cat; i++) {
struct log_category *cat = &tgt->categories[i];
/* skip empty entries in the array */
@@ -391,6 +395,8 @@ DEFUN(logging_level_force_all, logging_level_force_all_cmd,
{
struct log_target *tgt = osmo_log_vty2tgt(vty);
int level = log_parse_level(argv[0]);
+ if (!tgt)
+ return CMD_WARNING;
log_set_log_level(tgt, level);
return CMD_SUCCESS;
}
@@ -400,6 +406,8 @@ DEFUN(no_logging_level_force_all, no_logging_level_force_all_cmd,
NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)
{
struct log_target *tgt = osmo_log_vty2tgt(vty);
+ if (!tgt)
+ return CMD_WARNING;
log_set_log_level(tgt, 0);
return CMD_SUCCESS;
}