[asterisk-commits] oej: branch oej/sip_request_size_8556 r64652 - /team/oej/sip_request_size_855...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed May 16 07:16:11 MST 2007


Author: oej
Date: Wed May 16 09:16:10 2007
New Revision: 64652

URL: http://svn.digium.com/view/asterisk?view=rev&rev=64652
Log:
This branch is really bad

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=64652&r1=64651&r2=64652
==============================================================================
--- team/oej/sip_request_size_8556/channels/chan_sip.c (original)
+++ team/oej/sip_request_size_8556/channels/chan_sip.c Wed May 16 09:16:10 2007
@@ -611,6 +611,7 @@
 	int headers;            /*!< # of SIP Headers */
 	int method;             /*!< Method of this request */
 	int lines;              /*!< Body Content */
+	size_t datasize;        /*!< Current size of data payload */
 	unsigned int flags;     /*!< SIP_PKT Flags for this packet */
 	char *header[SIP_MAX_HEADERS];
 	char *line[SIP_MAX_LINES];
@@ -1627,10 +1628,13 @@
 		ast_log(LOG_DEBUG, "Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->callid);
 	}
 	if(p->initreq.data)
-		free(p->initreq.data);	/* De allocate memory before we overwrite */
+		free(p->initreq.data);	/* De-allocate memory before we overwrite */
 	/* Use this as the basis */
+	ast_log(LOG_DEBUG, "++++++++++++ 1. Data now: %s\n++++\n", req->data);
 	copy_request(&p->initreq, req);
+	ast_log(LOG_DEBUG, "++++++++++++ 2. Data now: %s\n++++\n", req->data);
 	parse_request(&p->initreq);
+	ast_log(LOG_DEBUG, "++++++++++++ 3. Data now: %s\n++++\n", req->data);
 	if (ast_test_flag(req, SIP_PKT_DEBUG))
 		ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
 }
@@ -1976,6 +1980,8 @@
 	struct sip_pkt *pkt;
 	int siptimer_a = DEFAULT_RETRANS;
 	int xmitres = 0;
+
+	ast_log(LOG_DEBUG, "+++++ Size of packet %d\n", len);
 
 	if (!(pkt = ast_calloc(1, sizeof(*pkt) + len + 1)))
 		return AST_FAILURE;
@@ -2168,8 +2174,11 @@
 /*! \brief Copy SIP request, parse it */
 static void parse_copy(struct sip_request *dst, const struct sip_request *src)
 {
+	if (dst->data)
+		free(dst->data);
 	memset(dst, 0, sizeof(*dst));
-	memcpy(dst->data, src->data, sizeof(dst->data));
+	dst->data = ast_calloc(1, src->datasize);
+	memcpy(dst->data, src->data, src->datasize);
 	dst->len = src->len;
 	parse_request(dst);
 }
@@ -2179,8 +2188,9 @@
 {
 	if (!req->lines) {
 		/* Add extra empty return. add_header() reserves 4 bytes so cannot be truncated */
-		snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n");
+		snprintf(req->data + req->len, req->datasize - req->len, "\r\n");
 		req->len += strlen(req->data + req->len);
+		ast_log(LOG_DEBUG, "+++++++ req len now %d\n", req->len);
 	}
 }
 
@@ -2223,6 +2233,7 @@
 	int res;
 
 	add_blank(req);
+	ast_log(LOG_DEBUG, "++++++++++ datasize now %d len %d\n", req->datasize, req->len);
 	if (sip_debug_test_pvt(p)) {
 		if (ast_test_flag(&p->flags[0], SIP_NAT_ROUTE))
 			ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
@@ -5333,7 +5344,7 @@
 /*! \brief Add header to SIP message */
 static int add_header(struct sip_request *req, const char *var, const char *value)
 {
-	int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */
+	int maxlen = req->datasize - 4 - req->len; /* 4 bytes are for two \r\n ? */
 
 	if (req->headers == SIP_MAX_HEADERS) {
 		ast_log(LOG_WARNING, "Out of SIP header space\n");
@@ -5362,6 +5373,9 @@
 		req->headers++;
 	else
 		ast_log(LOG_WARNING, "Out of SIP header space... Will generate broken SIP message\n");
+	ast_log(LOG_DEBUG, "+++++++ %d: req len now %d\n", req->headers, req->len);
+	if (req->headers < 8)
+		ast_log(LOG_DEBUG, "+++++++++++ !! %d : %s\nData: %s \n", req->headers, req->header[0], req->data);
 
 	return 0;	
 }
@@ -5384,15 +5398,15 @@
 	}
 	if (!req->lines) {
 		/* Add extra empty return */
-		snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n");
+		snprintf(req->data + req->len, req->datasize - req->len, "\r\n");
 		req->len += strlen(req->data + req->len);
 	}
-	if (req->len >= sizeof(req->data) - 4) {
+	if (req->len >= req->datasize - 4) {
 		ast_log(LOG_WARNING, "Out of space, can't add anymore\n");
 		return -1;
 	}
 	req->line[req->lines] = req->data + req->len;
-	snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
+	snprintf(req->line[req->lines], req->datasize - req->len, "%s", line);
 	req->len += strlen(req->line[req->lines]);
 	req->lines++;
 	return 0;	
@@ -5607,11 +5621,13 @@
 	/* Initialize a request */
 	memset(req, 0, sizeof(*req));
 	req->data = ast_calloc(1, SIP_MAX_PACKET);
+	req->datasize = 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);
+	snprintf(req->header[0], req->datasize, "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip);
 	req->len = strlen(req->header[0]);
 	req->headers++;
+	ast_log(LOG_DEBUG, "+++++++++ Len: %d Req header 0  %s\n", req->len, req->header[0]);
 	return 0;
 }
 
@@ -6450,12 +6466,14 @@
 	/* 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));
+
+	dst->data = ast_calloc(1, src->datasize);	/* Allocate new data */
+	memcpy(dst->data, src->data, src->datasize);	/* Copy data */
+
 	/* Now fix pointer arithmetic */
 	for (x=0; x < src->headers; x++)
 		dst->header[x] += offset;
@@ -6838,6 +6856,8 @@
 	} else
 		reqprep(&req, p, sipmethod, 0, 1);
 		
+	/* Skrep */
+	ast_log(LOG_DEBUG, "++++++++   INitialized packet, size %d\n", req.datasize);
 	if (p->options && p->options->auth)
 		add_header(&req, p->options->authheader, p->options->auth);
 	append_date(&req);
@@ -14928,6 +14948,7 @@
 	}
 	packetbuffer[res] = '\0';
 	req.data = ast_calloc(1, res + 1);
+	req.datasize = 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 */



More information about the asterisk-commits mailing list