<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/10133">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stats_statsd: sanitize statsd name<br><br>The statsd protocol use ':' as seperator between name and value.<br>It's not allowed to use the seperator in a name. Replace ':' with '.'<br>before sending the packet to the statsd server.<br><br>Change-Id: Ib46d08481e8ca04afd97cb9ae241e4e39c91ad66<br>---<br>M src/stats_statsd.c<br>1 file changed, 22 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/stats_statsd.c b/src/stats_statsd.c</span><br><span>index c11c013..5ae2570 100644</span><br><span>--- a/src/stats_statsd.c</span><br><span>+++ b/src/stats_statsd.c</span><br><span>@@ -68,6 +68,25 @@</span><br><span>    return srep;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Replace all illegal ':' in the stats name, but not when used as value seperator.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  ':' is used as seperator between the name and the value in the statsd protocol.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[inout] buf is a null terminated string containing name, value, unit. */</span><br><span style="color: hsl(120, 100%, 40%);">+static void osmo_stats_reporter_sanitize_name(char *buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     /* e.g. msc.loc_update_type:normal:1|c -> msc.loc_update_type.normal:1|c</span><br><span style="color: hsl(120, 100%, 40%);">+    * last is the seperator between name and value */</span><br><span style="color: hsl(120, 100%, 40%);">+    char *last = strrchr(buf, ':');</span><br><span style="color: hsl(120, 100%, 40%);">+       char *tmp = strchr(buf, ':');</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       if (!last)</span><br><span style="color: hsl(120, 100%, 40%);">+            return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     while (tmp < last) {</span><br><span style="color: hsl(120, 100%, 40%);">+               *tmp = '.';</span><br><span style="color: hsl(120, 100%, 40%);">+           tmp = strchr(buf, ':');</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,</span><br><span>       const char *name1, unsigned int index1, const char *name2, int64_t value,</span><br><span>    const char *unit)</span><br><span>@@ -134,8 +153,10 @@</span><br><span>                     return -EMSGSIZE;</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (nchars > 0)</span><br><span style="color: hsl(120, 100%, 40%);">+    if (nchars > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+          osmo_stats_reporter_sanitize_name(buf);</span><br><span>              msgb_trim(srep->buffer, msgb_length(srep->buffer) + nchars);</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span> </span><br><span>        if (!srep->agg_enabled)</span><br><span>           rc = osmo_stats_reporter_send_buffer(srep);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/10133">change 10133</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/10133"/><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: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib46d08481e8ca04afd97cb9ae241e4e39c91ad66 </div>
<div style="display:none"> Gerrit-Change-Number: 10133 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: lynxis lazus <lynxis@fe80.eu> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>