[asterisk-commits] oej: branch oej/sip_request_size_8556 r64563 -
/team/oej/sip_request_size_855...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed May 16 02:46:34 MST 2007
Author: oej
Date: Wed May 16 04:46:33 2007
New Revision: 64563
URL: http://svn.digium.com/view/asterisk?view=rev&rev=64563
Log:
Trying to make sure we can *read* SIP messages larger than 4096.
For sending, we still allocate a fix sized packet.
This is not tested yet, so please go ahead and test it. Bug report
#8556
Modified:
team/oej/sip_request_size_8556/channels/chan_sip.c
Modified: team/oej/sip_request_size_8556/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/sip_request_size_8556/channels/chan_sip.c?view=diff&rev=64563&r1=64562&r2=64563
==============================================================================
--- team/oej/sip_request_size_8556/channels/chan_sip.c (original)
+++ team/oej/sip_request_size_8556/channels/chan_sip.c Wed May 16 04:46:33 2007
@@ -614,7 +614,7 @@
unsigned int flags; /*!< SIP_PKT Flags for this packet */
char *header[SIP_MAX_HEADERS];
char *line[SIP_MAX_LINES];
- char data[SIP_MAX_PACKET];
+ char *data; /*!< Data, allocated as needed */
unsigned int sdp_start; /*!< the line number where the SDP begins */
unsigned int sdp_end; /*!< the line number where the SDP ends */
};
@@ -2205,6 +2205,11 @@
res = (reliable) ?
__sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) :
__sip_xmit(p, req->data, req->len);
+ /* Release allocated memory */
+ if (req->data) {
+ free(req->data);
+ req->data = NULL;
+ }
if (res > 0)
return 0;
return res;
@@ -2230,6 +2235,11 @@
res = (reliable) ?
__sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method) :
__sip_xmit(p, req->data, req->len);
+ /* Release allocated memory for this request */
+ if (req->data) {
+ free(req->data);
+ req->data = NULL;
+ }
return res;
}
@@ -5594,6 +5604,7 @@
{
/* Initialize a request */
memset(req, 0, sizeof(*req));
+ req->data = ast_calloc(1, SIP_MAX_PACKET);
req->method = sipmethod;
req->header[0] = req->data;
snprintf(req->header[0], sizeof(req->data), "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip);
@@ -5662,8 +5673,6 @@
const char *ot, *of;
int is_strict = FALSE; /*!< Strict routing flag */
- memset(req, 0, sizeof(struct sip_request));
-
snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text);
if (!seqno) {
@@ -6436,6 +6445,12 @@
{
long offset;
int x;
+ /* Do we already have a data field? THen free it */
+ if (dst->data)
+ free(dst->data);
+ dst->data = ast_calloc(1, sizeof(src->data)); /* Allocate new data */
+ memcpy(dst->data, src->data, sizeof(src->data)); /* Copy data */
+
offset = ((void *)dst) - ((void *)src);
/* First copy stuff */
memcpy(dst, src, sizeof(*dst));
@@ -6446,6 +6461,9 @@
dst->line[x] += offset;
dst->rlPart1 += offset;
dst->rlPart2 += offset;
+
+ if (option_debug > 3)
+ ast_log(LOG_DEBUG, "Copied SIP request\n");
}
/*! \brief Used for 200 OK and 183 early media
@@ -14891,9 +14909,11 @@
int nounlock;
int recount = 0;
int lockretry;
+ static char packetbuffer[65535]; /* Max packet size for UDP */
memset(&req, 0, sizeof(req));
- res = recvfrom(sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
+ //res = recvfrom(sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
+ res = recvfrom(sipsock, packetbuffer, sizeof(packetbuffer) - 1, 0, (struct sockaddr *)&sin, &len);
if (res < 0) {
#if !defined(__FreeBSD__)
if (errno == EAGAIN)
@@ -14904,11 +14924,9 @@
ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
return 1;
}
- if (option_debug && res == sizeof(req.data)) {
- ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
- req.data[sizeof(req.data) - 1] = '\0';
- } else
- req.data[res] = '\0';
+ packetbuffer[res] = '\0';
+ req.data = ast_calloc(1, res + 1);
+ memcpy(req.data, packetbuffer, res + 1);
req.len = res;
if(sip_debug_test_addr(&sin)) /* Set the debug flag early on packet level */
ast_set_flag(&req, SIP_PKT_DEBUG);
@@ -14923,8 +14941,11 @@
if (ast_test_flag(&req, SIP_PKT_DEBUG))
ast_verbose("--- (%d headers %d lines)%s ---\n", req.headers, req.lines, (req.headers + req.lines == 0) ? " Nat keepalive" : "");
- if (req.headers < 2) /* Must have at least two headers */
+ if (req.headers < 2) { /* Must have at least two headers */
+ if (req.data)
+ free(req.data);
return 1;
+ }
/* Process request, with netlock held, and with usual deadlock avoidance */
for (lockretry = 100; lockretry > 0; lockretry--) {
@@ -14935,6 +14956,8 @@
if (p == NULL) {
if (option_debug)
ast_log(LOG_DEBUG, "Invalid SIP message - rejected , no callid, len %d\n", req.len);
+ if (req.data)
+ free(req.data);
ast_mutex_unlock(&netlock);
return 1;
}
@@ -14962,6 +14985,9 @@
transmit_response(p, "503 Server error", &req); /* We must respond according to RFC 3261 sec 12.2 */
/* XXX We could add retry-after to make sure they come back */
append_history(p, "LockFail", "Owner lock failed, transaction failed.");
+ if (req.data)
+ free(req.data);
+ ast_mutex_unlock(&netlock);
return 1;
}
nounlock = 0;
@@ -14974,6 +15000,8 @@
if (p->owner && !nounlock)
ast_channel_unlock(p->owner);
ast_mutex_unlock(&p->lock);
+ if (req.data)
+ free(req.data);
ast_mutex_unlock(&netlock);
if (recount)
ast_update_use_count();
More information about the asterisk-commits
mailing list