<p>Neels Hofmeyr has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/11168">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty logging: fix crash when missing 'logging enable'<br><br>We must explicitly check the return value of osmo_log_vty2tgt(), or may run<br>into a segfault. I wasn't aware of this and introduced numerous such cases in<br>I36f17c131cc70ce5a1aef62fd9693097de230cd4.<br><br>Reproduce: on the VTY, do not issue 'logging enable', invoke 'logging level<br>force-all LEVEL' first.<br><br>Show in logging_vty_test.vty that this situation is now again amended by<br>telling the user that logging was not enabled.<br><br>Related: OS#3611<br>Change-Id: Id11702d1801d6654ca5e5a51b597a0d802e2e8dd<br>---<br>M src/vty/logging_vty.c<br>M tests/logging/logging_vty_test.vty<br>2 files changed, 11 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/68/11168/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c</span><br><span>index 31edb52..f3e1419 100644</span><br><span>--- a/src/vty/logging_vty.c</span><br><span>+++ b/src/vty/logging_vty.c</span><br><span>@@ -364,6 +364,10 @@</span><br><span>       struct log_target *tgt = osmo_log_vty2tgt(vty);</span><br><span>      int level = log_parse_level(argv[0]);</span><br><span>        int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      if (!tgt)</span><br><span style="color: hsl(120, 100%, 40%);">+             return CMD_WARNING;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>        for (i = 0; i < osmo_log_info->num_cat; i++) {</span><br><span>                 struct log_category *cat = &tgt->categories[i];</span><br><span>               /* skip empty entries in the array */</span><br><span>@@ -391,6 +395,8 @@</span><br><span> {</span><br><span>     struct log_target *tgt = osmo_log_vty2tgt(vty);</span><br><span>      int level = log_parse_level(argv[0]);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!tgt)</span><br><span style="color: hsl(120, 100%, 40%);">+             return CMD_WARNING;</span><br><span>  log_set_log_level(tgt, level);</span><br><span>       return CMD_SUCCESS;</span><br><span> }</span><br><span>@@ -400,6 +406,8 @@</span><br><span>       NO_STR LOGGING_STR LEVEL_STR NO_FORCE_ALL_STR)</span><br><span> {</span><br><span>  struct log_target *tgt = osmo_log_vty2tgt(vty);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!tgt)</span><br><span style="color: hsl(120, 100%, 40%);">+             return CMD_WARNING;</span><br><span>  log_set_log_level(tgt, 0);</span><br><span>   return CMD_SUCCESS;</span><br><span> }</span><br><span>diff --git a/tests/logging/logging_vty_test.vty b/tests/logging/logging_vty_test.vty</span><br><span>index 0eedbe3..b190927 100644</span><br><span>--- a/tests/logging/logging_vty_test.vty</span><br><span>+++ b/tests/logging/logging_vty_test.vty</span><br><span>@@ -28,6 +28,9 @@</span><br><span> logging_vty_test(config)# no log stderr</span><br><span> logging_vty_test(config)# exit</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+logging_vty_test# logging level force-all notice</span><br><span style="color: hsl(120, 100%, 40%);">+Logging was not enabled.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> logging_vty_test# logging enable</span><br><span> logging_vty_test# logging filter all 1</span><br><span> logging_vty_test# logging print category-hex 0</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/11168">change 11168</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/11168"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id11702d1801d6654ca5e5a51b597a0d802e2e8dd </div>
<div style="display:none"> Gerrit-Change-Number: 11168 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>