<p>My solution to <a href="https://github.com/OpenSIPS/opensips/issues/531" class="issue-link" title="{s.fill.right,&lt;space&gt;,} transformation uses 100% CPU">#531</a> caused by _tr_parse_sparam attempting to parse an empty argument.  The 100% CPU is caused by an infinite loop in <code>static void trans_fill_right(pv_value_t *val, str pad, int len)</code> (transformations.c:129) since the while loop <code>while (len &gt; 0)</code> depends on pad.len being decremented from len (<code>len -= pad.len;</code>) which never happens because pad.len = 0.</p>

<p>There are probably a couple different ways to incorporate this check, but this works.  Applying this pull request before my previous pull request, <a href="https://github.com/OpenSIPS/opensips/pull/530" class="issue-link" title="add width string transformation">#530</a>, will probably cause it to be invalid in case it is approved as well.</p>

<p>Here is the backtrace that led me to the above conclusion:</p>

<pre><code>(gdb) bt
#0  trans_fill_right (len=1, val=&lt;optimized out&gt;, pad=...)
    at transformations.c:153
#1  tr_eval_string (msg=&lt;optimized out&gt;, tp=&lt;optimized out&gt;, 
    subtype=&lt;optimized out&gt;, val=&lt;optimized out&gt;) at transformations.c:707
#2  0x00000000004b97cd in run_transformations (msg=msg@entry=0x7fffffffdcf0, 
    tr=&lt;optimized out&gt;, val=val@entry=0x7fffffffd580) at transformations.c:78
#3  0x00000000004f5ae9 in pv_get_spec_value (msg=&lt;optimized out&gt;, 
    sp=0x7ffff745c3c8, value=0x7fffffffd580) at pvar.c:4122
#4  0x00000000004f75d0 in pv_printf (msg=msg@entry=0x7fffffffdcf0, 
    list=list@entry=0x7ffff745c3b8, buf=&lt;optimized out&gt;, 
    len=len@entry=0x7fffffffd5e4) at pvar.c:4194
#5  0x00000000004fce0c in pv_printf (msg=msg@entry=0x7fffffffdcf0, 
    list=list@entry=0x7ffff745c3b8, buf=&lt;optimized out&gt;, 
    len=len@entry=0x7fffffffd5e4) at pvar.c:4173
#6  0x0000000000484799 in xl_print_log (len=0x7fffffffd5e4, 
    list=0x7ffff745c3b8, msg=0x7fffffffdcf0) at xlog.c:65
#7  xlog_1 (msg=msg@entry=0x7fffffffdcf0, 
    frm=0x7ffff745c3b8 "p^B\367\377\177", str2=&lt;optimized out&gt;) at xlog.c:114
#8  0x0000000000459d46 in do_action (a=a@entry=0x7ffff7425f08, 
    msg=msg@entry=0x7fffffffdcf0) at action.c:1652
#9  0x000000000045dce1 in run_action_list (msg=&lt;optimized out&gt;, 
    a=&lt;optimized out&gt;) at action.c:169
#10 run_actions (msg=0x7fffffffdcf0, a=&lt;optimized out&gt;) at action.c:134
#11 run_top_route (a=&lt;optimized out&gt;, msg=msg@entry=0x7fffffffdcf0)
    at action.c:209
#12 0x00000000004a0732 in run_startup_route () at route.c:2381
#13 0x00000000005905ce in udp_start_nofork () at net/net_udp.c:363
#14 0x000000000041a75e in main_loop () at main.c:665
#15 main (argc=&lt;optimized out&gt;, argv=&lt;optimized out&gt;) at main.c:1248
</code></pre>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>&nbsp;&nbsp;<a href='https://github.com/OpenSIPS/opensips/pull/532'>https://github.com/OpenSIPS/opensips/pull/532</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>check for invalid parameter passed to _tr_parse_sparam #531</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/OpenSIPS/opensips/pull/532/files#diff-0">transformations.c</a>
    (7)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/OpenSIPS/opensips/pull/532.patch'>https://github.com/OpenSIPS/opensips/pull/532.patch</a></li>
  <li><a href='https://github.com/OpenSIPS/opensips/pull/532.diff'>https://github.com/OpenSIPS/opensips/pull/532.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/pull/532">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOciQ5wuOE2eGvLn-UgDY_xE_9w-3Wtks5oOTtygaJpZM4EwKXu.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/OpenSIPS/opensips/pull/532"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>