<p></p>
<h3>Description</h3>
<p>We noticed random errors from jansson module when:</p>
<pre><code>xlog("L_NOTICE", "**** PRE '«$avp(i:901)»' - [% logres %]\n");
jansson_set("str", "cc_sub", "$avp(s:caller_concurrent_calls_count)", "$(avp(i:901)[*])");
</code></pre>
<pre><code>May 14 10:11:37 sp1 proxy[23633]: ERROR: jansson [jansson_funcs.c:219]: janssonmod_set(): result has json error at line 1: end of file expected near 'xMTAwMiIsImxucF'                                                                                      
May 14 10:11:37 sp1 proxy[23633]: ERROR: jansson [jansson_funcs.c:219]: janssonmod_set(): result has json error at line 1: end of file expected near '0'
May 14 10:11:37 sp1 proxy[23633]: ERROR: jansson [jansson_funcs.c:219]: janssonmod_set(): result has json error at line 1: end of file expected near 'TEwMDEiLCJkX'
</code></pre>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p><code> jansson_set(type, key/path, value, result)</code></p>
<p>Using a long json result, in my tests longer than 400 chars fires the ERROR</p>
<h4>Log Messages</h4>
<pre><code>May 14 10:11:37 sp1 proxy[23633]: NOTICE: <script>: Setting acc destination-leg for uuid '«0d5845e9-2cd1-4b1e-bbc4-6ca9102f864e»': '«{"gpp":["long long long long","long long long long","long long long long","long long long long","long long long long","l
ong long long long","long long long long","long long long long","long long long long","long long long long"],"plu":0,"s_id":"","c_id":"","a_id":315,"dialed":"4311001","uuid":"0d5845e9-2cd1-4b1e-bbc4-6ca9102f864e","u":"testuser1001","d":"spce.test","u_in
":"4311001","d_in":"spce.test","lcr":0,"lnp_p":"","u_out":"testuser1001","lnp_t":"","fci":"","cc_quota":"","cc_sub":"","cc_cust":""}»' - R=«sip:conf=4311001@conference.local» ID=«NGCP%invite_conference_update%///1-23982@127.126.0.1_pbx-1» UA='<null>'
May 14 10:11:37 sp1 proxy[23633]: NOTICE: <script>: **** PRE '«{"gpp":[null,null,null,null,null,null,null,null,null,null],"clir":0,"uuid":"adeff08b-bd66-4578-8a01-194185d06827","u":"testuser1002","d":"spce.test","cli":"43110011002","s_id":"","c_id":"","
a_id":315,"pau":"","par":"","s":"call","ip":"127.126.0.1","t":1589443897.908021,"lnp_p":"","cli_out":"43110011002","lnp_t":"","pai":"","div":"","cid":"","u2u":"","lcr":0,"cc_quota":"","cc_sub":"","cc_cust":""}»' - ID=«NGCP%invite_conference_update%///1-
23982@127.126.0.1_pbx-1» UA='<null>'
May 14 10:11:37 sp1 proxy[23633]: ERROR: jansson [jansson_funcs.c:219]: janssonmod_set(): result has json error at line 1: end of file expected near 'xMTAwMiIsImxucF'
May 14 10:11:37 sp1 proxy[23633]: ERROR: jansson [jansson_funcs.c:219]: janssonmod_set(): result has json error at line 1: end of file expected near '0'

</code></pre>
<h3>Possible Solutions</h3>
<p>In my fast check I notice the result is forced to end in '\0'. Preparing a PR with a solution.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<p>This is Sipwise's version but with no jansson patches at all</p>
<pre><code>version: kamailio 5.3.4 (x86_64/linux) 
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, NO_SIG_DEBUG, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown 
compiled with gcc 8.3.0
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2327">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZNH4RH57VG5BP2MRRTRROTBXANCNFSM4NAO5I6A">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZJFEMTO5SJRJZE7MEDRROTBXA5CNFSM4NAO5I6KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4JGWLLDQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2327",
"url": "https://github.com/kamailio/kamailio/issues/2327",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>