[asterisk-commits] russell: branch bbryant/sip-tcptls r73124 - /team/bbryant/sip-tcptls/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 3 11:41:48 CDT 2007
Author: russell
Date: Tue Jul 3 11:41:48 2007
New Revision: 73124
URL: http://svn.digium.com/view/asterisk?view=rev&rev=73124
Log:
Fix a seg fault that could occur when the remote end closes the connection
Modified:
team/bbryant/sip-tcptls/channels/chan_sip.c
Modified: team/bbryant/sip-tcptls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/channels/chan_sip.c?view=diff&rev=73124&r1=73123&r2=73124
==============================================================================
--- team/bbryant/sip-tcptls/channels/chan_sip.c (original)
+++ team/bbryant/sip-tcptls/channels/chan_sip.c Tue Jul 3 11:41:48 2007
@@ -1729,20 +1729,23 @@
static void sip_pvt_unlock(struct sip_pvt *);
/*! \brief SIP TCP helper function */
-static void *sip_tcp_helper_thread(void *data) {
- struct server_instance *ser = data;
+static void *sip_tcp_helper_thread(void *data)
+{
+ struct sip_pvt *pvt = data;
+ struct server_instance *ser = pvt->socket.ser;
int cl;
char buf[1024];
struct sip_request req = { 0, }, reqcpy = { 0, };
for (;;) {
bzero(req.data, sizeof(req.data));
- fgets(req.data, sizeof(req.data), ser->f);
- req.len = strlen(req.data);
+ req.len = 0;
while (req.len < 4 || strncmp((char *)&req.data + req.len - 4, "\r\n\r\n", 4)) {
- if(!fgets(buf, sizeof(buf), ser->f))
+ if (!fgets(buf, sizeof(buf), ser->f)) {
+ pvt->socket.ser = NULL;
return NULL;
+ }
strncat(req.data, buf, sizeof(req.data) - req.len);
req.len = strlen(req.data);
@@ -1754,8 +1757,10 @@
if (sscanf(get_header(&reqcpy, "Content-Length"), "%d", &cl)) {
while (cl > 0) {
- if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f))
+ if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f)) {
+ pvt->socket.ser = NULL;
return NULL;
+ }
cl -= strlen(buf);
strncat(req.data, buf, sizeof(req.data) - req.len);
@@ -16067,13 +16072,14 @@
return s.port == STANDARD_SIP_PORT;
}
-static void sip_prepare_socket(struct sip_pvt *p) {
+static void sip_prepare_socket(struct sip_pvt *p)
+{
struct sip_socket *s = &p->socket;
- if(s->fd != -1)
+ if (s->fd != -1)
return;
- if(!(s->type & SIP_TRANSPORT_UDP)) {
+ if (!(s->type & SIP_TRANSPORT_UDP)) {
char name[] = "SIP socket";
struct server_args ca;
@@ -16088,7 +16094,7 @@
s->fd = ca.accept_fd;
- if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_helper_thread, s->ser)) {
+ if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_helper_thread, p)) {
ast_log(LOG_DEBUG, "Unable to launch '%s'.", ca.name);
close(ca.accept_fd);
s->fd = ca.accept_fd = -1;
More information about the asterisk-commits
mailing list