Bugzilla – Attachment 8475 Details for
Bug 7787
SIP server closes the TCP connection when it receives an invalid message
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Make the SIP server more robust by not exiting on invalid input, but rather issue a resend response.
0001-Bug-7787-Make-the-SIP-server-much-more-robust.-Be-li.patch (text/plain), 4.23 KB, created by
Marc Balmer
on 2012-03-22 09:38:45 UTC
(
hide
)
Description:
Make the SIP server more robust by not exiting on invalid input, but rather issue a resend response.
Filename:
MIME Type:
Creator:
Marc Balmer
Created:
2012-03-22 09:38:45 UTC
Size:
4.23 KB
patch
obsolete
>From 08e9813ccc7d329daf4e6624869550e6220a19e0 Mon Sep 17 00:00:00 2001 >From: Marc Balmer <marc@msys.ch> >Date: Wed, 21 Mar 2012 18:18:45 +0100 >Subject: [PATCH] Bug 7787: Make the SIP server much more robust. Be liberal in what we > accept, but strict in what we send: Never exit the server process, but > send a SC_RESEND message (96) to the client if we received anything we don't > understand. This is consistent with SIP server implementations of other > ILSs. > >--- > C4/SIP/SIPServer.pm | 21 +++++++++------------ > C4/SIP/Sip.pm | 8 -------- > C4/SIP/Sip/MsgType.pm | 4 +++- > 3 files changed, 12 insertions(+), 21 deletions(-) > >diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm >index c6de11e..137fd91 100644 >--- a/C4/SIP/SIPServer.pm >+++ b/C4/SIP/SIPServer.pm >@@ -21,7 +21,7 @@ use constant LOG_SIP => "local6"; # Local alias for the logging facility > use vars qw(@ISA $VERSION); > > BEGIN { >- $VERSION = 1.02; >+ $VERSION = 1.03; > @ISA = qw(Net::Server::PreFork); > } > >@@ -269,32 +269,29 @@ sub sip_protocol_loop { > # In short, we'll take any valid message here. > #my $expect = SC_STATUS; > my $expect = ''; >- my $strikes = 3; >- while ($input = Sip::read_SIP_packet(*STDIN)) { >+ while (1) { >+ $input = Sip::read_SIP_packet(*STDIN); >+ unless ($input) { >+ print("96$CR"); >+ next; >+ } > # begin input hacks ... a cheap stand in for better Telnet layer > $input =~ s/^[^A-z0-9]+//s; # Kill leading bad characters... like Telnet handshakers > $input =~ s/[^A-z0-9]+$//s; # Same on the end, should get DOSsy ^M line-endings too. > while (chomp($input)) {warn "Extra line ending on input";} > unless ($input) { >- if ($strikes--) { >- syslog("LOG_ERR", "sip_protocol_loop: empty input skipped"); >- next; >- } else { >- syslog("LOG_ERR", "sip_protocol_loop: quitting after too many errors"); >- die "sip_protocol_loop: quitting after too many errors"; >- } >+ syslog("LOG_ERR", "sip_protocol_loop: empty input skipped"); >+ next; > } > # end cheap input hacks > my $status = Sip::MsgType::handle($input, $self, $expect); > if (!$status) { > syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2)); >- die "sip_protocol_loop: failed Sip::MsgType::handle('$input', $self, '$expect')"; > } > next if $status eq REQUEST_ACS_RESEND; > if ($expect && ($status ne $expect)) { > # We received a non-"RESEND" that wasn't what we were expecting. > syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input); >- die "sip_protocol_loop: exiting: expected '$expect', received '$status'"; > } > # We successfully received and processed what we were expecting > $expect = ''; >diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm >index 337cc0e..0ff01dd 100644 >--- a/C4/SIP/Sip.pm >+++ b/C4/SIP/Sip.pm >@@ -156,7 +156,6 @@ sub read_SIP_packet { > # local $/ = "\r"; # don't need any of these here. use whatever the prevailing $/ is. > local $/ = "\015"; # proper SPEC: (octal) \015 = (hex) x0D = (dec) 13 = (ascii) carriage return > { # adapted from http://perldoc.perl.org/5.8.8/functions/readline.html >- for ( my $tries = 1 ; $tries <= 3 ; $tries++ ) { > undef $!; > $record = readline($fh); > if ( defined($record) ) { >@@ -171,14 +170,7 @@ sub read_SIP_packet { > while ( chomp($record) ) { 1; } > > $record and last; # success >- } else { >- if ($!) { >- syslog( "LOG_DEBUG", "read_SIP_packet (try #$tries) ERROR: $! $@" ); >- # die "read_SIP_packet ERROR: $!"; >- warn "read_SIP_packet ERROR: $! $@"; >- } > } >- } > } > if ($record) { > my $len2 = length($record); >diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm >index 6a11d0e..d8bfd5b 100644 >--- a/C4/SIP/Sip/MsgType.pm >+++ b/C4/SIP/Sip/MsgType.pm >@@ -405,7 +405,9 @@ sub handle { > } > unless ($self->{handler}) { > syslog("LOG_WARNING", "No handler defined for '%s'", $msg); >- return undef; >+ $last_response = REQUEST_SC_RESEND; >+ print("$last_response\r"); >+ return REQUEST_ACS_RESEND; > } > return($self->{handler}->($self, $server)); # FIXME > # FIXME: Use of uninitialized value in subroutine entry >-- >1.7.2.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7787
:
8475
|
8501
|
8502
|
8511
|
10012
|
10362
|
10392