<p>By calling remove_hf using a wildcard and the calling remove_hf for a specific header that was already removed previously by the wildcard pattern triggers malformed messages and sometimes crashes.</p>

<p>Example of a malformed packet triggered by:<br>
...<br>
    if (is_present_hf("User-Agent")) {<br>
        remove_hf("User-A*", "g");<br>
        remove_hf("User-Agent");<br>
    }<br>
...</p>

<p>And the outgoing INVITE looks like:<br>
INVITE sip:4165551111@192.168.2.97:5062 SIP/2.0.<br>
Record-Route: <a>sip:192.168.2.3;lr;did=1.3b4c7b54</a>.<br>
Via: SIP/2.0/UDP 192.168.2.3:5060;branch=z9hG4bKa078.545ba521.0.<br>
Via: SIP/2.0/UDP 192.168.2.2:5060;received=192.168.2.2;branch=z9hG4bK17356ec3;rport=5060.<br>
Max-Forwards: 69.<br>
From: "Ovidiu Sas PBX " <a>sip:osas@192.168.2.2</a>;tag=as77cfb2a7.<br>
To: <a>sip:4165551111@192.168.2.3</a>.<br>
Contact: <a>sip:osas@192.168.2.2:5060</a>.<br>
Call-ID: 403944a939ca8ea85b2b2b344cc33ed5@192.168.2.2:5060.<br>
CSeq: 102 INVITE.<br>
 2013 17:47:25 GMT.<br>
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH.<br>
Supported: replaces, timer.<br>
Content-Type: application/sdp.<br>
Content-Length: 290.</p>

<p>See the Cseq header.  The received headers:<br>
Call-ID: 403944a939ca8ea85b2b2b344cc33ed5@192.168.2.2:5060.<br>
CSeq: 102 INVITE.<br>
User-Agent: PBX.<br>
Date: Mon, 25 Nov 2013 17:47:25 GMT.<br>
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH.</p>

<p>The Date header was overwritten.</p>

<p>Regards,<br>
Ovidiu Sas</p>

<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/issues/137'>view it on GitHub</a>.<img src='https://github.com/notifications/beacon/cHRwG-eeZpfKR_UBFXzvRBWmpwgoA3_meRsx-0OpPzN4SFz1qKLcEqm-DtPI0z3p.gif' height='1' width='1'></p>