aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-31 22:58:54 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-31 22:58:54 +0000
commit916e56aa98ba1b4ffba0f9bf4be89f69079fb0e8 (patch)
tree7d6837b9ec79e3e44c325197fc8eb3ce1ed1d1da /channels/chan_sip.c
parent3021b77d121bfe5d1b2937889017bca32f8cb523 (diff)
handle improperly formatted initial requests properly (issue #5483)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6911 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_sip.c')
-rwxr-xr-xchannels/chan_sip.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index e767d0a93..fa0431aff 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -3295,7 +3295,7 @@ static void parse_request(struct sip_request *req)
*c = 0;
if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "Header: %s (%d)\n", req->header[f], (int) strlen(req->header[f]));
+ ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
if (ast_strlen_zero(req->header[f])) {
/* Line by itself means we're now in content */
c++;
@@ -3313,8 +3313,11 @@ static void parse_request(struct sip_request *req)
c++;
}
/* Check for last header */
- if (!ast_strlen_zero(req->header[f]))
+ if (!ast_strlen_zero(req->header[f])) {
+ if (sipdebug && option_debug > 3)
+ ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
f++;
+ }
req->headers = f;
/* Now we process any mime content */
f = 0;
@@ -10809,6 +10812,7 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc
char iabuf[INET_ADDRSTRLEN];
int debug = sip_debug_test_pvt(p);
char *e;
+ int error = 0;
/* Clear out potential response */
memset(&resp, 0, sizeof(resp));
@@ -10818,10 +10822,17 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc
cmd = req->header[0];
/* Must have Cseq */
- if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq))
- return -1;
- if (sscanf(cseq, "%d%n", &seqno, &len) != 1) {
- ast_log(LOG_DEBUG, "No seqno in '%s'\n", cmd);
+ if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) {
+ ast_log(LOG_ERROR, "Missing Cseq. Dropping this SIP message, it's incomplete.\n");
+ error = 1;
+ }
+ if (!error && sscanf(cseq, "%d%n", &seqno, &len) != 1) {
+ ast_log(LOG_ERROR, "No seqno in '%s'. Dropping incomplete message.\n", cmd);
+ error = 1;
+ }
+ if (error) {
+ if (!p->initreq.header) /* New call */
+ ast_set_flag(p, SIP_NEEDDESTROY); /* Make sure we destroy this dialog */
return -1;
}
/* Get the command XXX */
@@ -11007,6 +11018,9 @@ static int sipsock_read(int *id, int fd, short events, void *ignore)
ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
return 1;
}
+ if (res == sizeof(req.data)) {
+ ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
+ }
req.data[res] = '\0';
req.len = res;
if(sip_debug_test_addr(&sin))
@@ -11053,7 +11067,11 @@ retrylock:
append_history(p, "Rx", tmp);
}
nounlock = 0;
- handle_request(p, &req, &sin, &recount, &nounlock);
+ if (handle_request(p, &req, &sin, &recount, &nounlock) == -1) {
+ /* Request failed */
+ ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>");
+ }
+
if (p->owner && !nounlock)
ast_mutex_unlock(&p->owner->lock);
ast_mutex_unlock(&p->lock);