<h3>Description</h3>
<p>While testing to implement an IMS AS, I used the PUA_REGINFO module to receive details about the SIP registration. PUA_REGINFO module uses PUA and USRLOC modules.</p>
<p>However, a couple of issues was found including a crash:</p>
<ol>
<li>Crash when processing SIP Notify with registration terminated info.</li>
<li>Randomly fails storing data to USRLOC, (entries already exists)</li>
<li>Saves corrupt data to database use_domain is set in usrloc but domain not provided in Notify request</li>
</ol>
<h3>Troubleshooting</h3>
<p>I am pretty new to Kamailio, but my findings are the following in notify.c</p>
<ol>
<li>
<p>PUA_REGINFO modules, deletes the record with "ul.delete_urecord(...)" and later down in the code calls  "if (ul_record) ul.release_urecord(ul_record);".   Crashes on the release_urecord call.<br>
My assumption without knowing to much about userloc is that release can not be called on a deleted record. Hence it should be enough to set ul_record = NULL after calling "ul.delete_urecord(...)" to not call release_urecord later on.</p>
</li>
<li>
<p>It looks like there is an issue handling parallell request.<br>
Without knowing too much, it replacing sruid_next(..) with sruid_next_safe() resolves the issue.<br>
Also, the static variable of type ucontact_info_t should probably become local as well.</p>
</li>
<li>
<p>Maybe incorrect to set use_domain to 1 when using the module, however I think it should be failsafe and not store garbage data in to database.  Not looked into this issue.</p>
</li>
</ol>
<h4>Reproduction</h4>
<p>Send Notify request with REGINFO body for registration and unregistration and forward it to the module according to the documentation of PUA_REGINFO.</p>
<h4>Debugging Data</h4>
<p>Attaching SIPp scenario.<br>
Changing code according to 1) and 2) make the SIPp script runs and no critical issues seen.<br>
(Have too less experience to ensure that no memleaks are introduced or still present in the module code)</p>


  
    <code>  NOTIFY sip:[remote_ip] SIP/2.0                                                                                                                                                                        
  Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]                                                                                                                                      
  From: <sip:[field0]@[field1]>;tag=[call_number]                                                                                                                                                       
  To: <sip:[field0]@[field1]>                                                                                                                                                                           
  Call-ID: [call_id]                                                                                                                                                                                    
  CSeq: 1 NOTIFY                                                                                                                                                                                        
  Contact: sip:[field0]@[local_ip]:[local_port]                                                                                                                                                         
  Max-Forwards: 70                                                                                                                                                                                      
  Expires: 1800                                                                                                                                                                                         
  Event: reg                                                                                                                                                                                            
  User-Agent: SIPp/Linux                                                                                                                                                                                
  Subscription-State: active;expires=6888                                                                                                                                                               
  Content-Type: application/reginfo+xml                                                                                                                                                                 
  Content-Length: [len]                                                                                                                                                                                 
                                                                                                                                                                                                        
  <?xml version="1.0"?>                                                                                                                                                                                 
  <reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="2" state="full">                                                                                                                             
    <registration aor="sip:[field0]@mnc001.mcc001.3gppnetwork.org" id="0x7feff71118f8" state="active">                                                                                                  
      <contact id="0x7feff7126e58" state="active" event="registered" expires="595" q="0.500">                                                                                                           
          <uri>sip:[field0]@192.168.55.103:21061;ob;alias=192.168.55.103~21061~1</uri>                                                                                                                  
          <unknown-param name="+g.3gpp.smsip"></unknown-param>                                                                                                                                          
          <unknown-param name="q">"0.5"</unknown-param>                                                                                                                                                 
      </contact>                                                                                                                                                                                        
      </registration>                                                                                                                                                                                   
 </reginfo>                                                                                                                                                                                             
]]>
</code>
  
  
  
  
  
    <code> NOTIFY sip:[remote_ip] SIP/2.0                                                                                                                                                                         
 Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]                                                                                                                                       
 From: <sip:[field0]@[field1]>;tag=[call_number]                                                                                                                                                        
 To: <sip:[field0]@[field1]>                                                                                                                                                                            
 Call-ID: [call_id]                                                                                                                                                                                     
 CSeq: 2 NOTIFY                                                                                                                                                                                         
 Contact: sip:[field0]@[local_ip]:[local_port]                                                                                                                                                          
 Max-Forwards: 70                                                                                                                                                                                       
 Expires: 1800                                                                                                                                                                                          
 User-Agent: SIPp/Linux                                                                                                                                                                                 
 Event: reg                                                                                                                                                                                             
 Subscription-State: active;expires=6888                                                                                                                                                                
 Content-Type: application/reginfo+xml                                                                                                                                                                  
 Content-Length: [len]                                                                                                                                                                                  
                                                                                                                                                                                                        
 <?xml version="1.0"?>                                                                                                                                                                                  
 <reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="3" state="full">                                                                                                                              
   <registration aor="sip:[field0]@mnc001.mcc001.3gppnetwork.org" id="0x7feff71118f8" state="terminated">
     <contact id="0x1" state="terminated" event="expired" expires="0" q="0.000">
       <uri>sip:[field0]@192.168.55.103:21061;ob;alias=192.168.55.103~21061~1</uri>
     </contact>
   </registration>
 </reginfo>
]]>
</code>
  
  
  

<h4>Log Messages</h4>
<h4>SIP Traffic</h4>
<h3>Possible Solutions</h3>
<p>See troubleshooting.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>5.1.4
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>Debian 8.11
</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/1579">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZRxLbEFxu5D6HLJ5fb1DSoYkMOh6ks5uCUW-gaJpZM4U-fMk">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZTB-WnSMMejBMxGhOQwDgFuTVhrjks5uCUW-gaJpZM4U-fMk.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Issues with PUA_REGINFO module (#1579)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1579"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1579",
"url": "https://github.com/kamailio/kamailio/issues/1579",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Issues with PUA_REGINFO module (#1579)",
"sections": [
{
"text": "",
"activityTitle": "**Lars Olsson**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@lasseo",
"facts": [
{
"name": "Repository: ",
"value": "kamailio/kamailio"
},
{
"name": "Issue #: ",
"value": 1579
}
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1579,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1579\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1579"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 351925028\n}"
}
],
"themeColor": "26292E"
}
]</script>