Module: sems
Branch: master
Commit: c36eb930a3c82c0c5381b1c060961b5fef272bbb
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=c36eb930a3c82c0c5381b1c060961b5fef272bbb

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Wed Feb  8 14:47:05 2012 +0100

sip: add end-of-buffer parameter to parse_headers().

---

 core/SipCtrlInterface.cpp |   14 +++++++-------
 core/sip/parse_header.cpp |    4 ++--
 core/sip/parse_header.h   |    2 +-
 core/sip/sip_parser.cpp   |    8 +++-----
 core/sip/sip_parser.h     |    2 +-
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp
index 06ecaab..a894a42 100644
--- a/core/SipCtrlInterface.cpp
+++ b/core/SipCtrlInterface.cpp
@@ -149,10 +149,10 @@ int SipCtrlInterface::send(AmSipRequest &req,
     // Max-Forwards
     
     char* c = (char*)req.from.c_str();
-    int err = parse_headers(msg,&c);
+    int err = parse_headers(msg,&c,c+req.from.length());
 
     c = (char*)req.to.c_str();
-    err = err || parse_headers(msg,&c);
+    err = err || parse_headers(msg,&c,c+req.to.length());
 
     if(err){
        ERROR("Malformed To or From header\n");
@@ -172,7 +172,7 @@ int SipCtrlInterface::send(AmSipRequest &req,
     if(!req.contact.empty()){
 
        c = (char*)req.contact.c_str();
-       err = parse_headers(msg,&c);
+       err = parse_headers(msg,&c,c+req.contact.length());
        if(err){
            ERROR("Malformed Contact header\n");
            delete msg;
@@ -183,7 +183,7 @@ int SipCtrlInterface::send(AmSipRequest &req,
     if(!req.route.empty()){
        
        c = (char*)req.route.c_str();
-       err = parse_headers(msg,&c);
+       err = parse_headers(msg,&c,c+req.route.length());
        
        if(err){
            ERROR("Route headers parsing failed\n");
@@ -197,7 +197,7 @@ int SipCtrlInterface::send(AmSipRequest &req,
        
        c = (char*)req.hdrs.c_str();
        
-       err = parse_headers(msg,&c);
+       err = parse_headers(msg,&c,c+req.hdrs.length());
        
        if(err){
            ERROR("Additional headers parsing failed\n");
@@ -314,7 +314,7 @@ int SipCtrlInterface::send(const AmSipReply &rep)
     if(!rep.hdrs.empty()) {
 
        char* c = (char*)rep.hdrs.c_str();
-       int err = parse_headers(&msg,&c);
+       int err = parse_headers(&msg,&c,c+rep.hdrs.length());
        if(err){
            ERROR("Malformed additional header\n");
            return -1;
@@ -324,7 +324,7 @@ int SipCtrlInterface::send(const AmSipReply &rep)
     if(!rep.contact.empty()){
 
        char* c = (char*)rep.contact.c_str();
-       int err = parse_headers(&msg,&c);
+       int err = parse_headers(&msg,&c,c+rep.contact.length());
        if(err){
            ERROR("Malformed Contact header\n");
            return -1;
diff --git a/core/sip/parse_header.cpp b/core/sip/parse_header.cpp
index ed2302a..03de334 100644
--- a/core/sip/parse_header.cpp
+++ b/core/sip/parse_header.cpp
@@ -260,7 +260,7 @@ void add_parsed_header(list<sip_header*>& hdrs, sip_header* 
hdr)
     hdrs.push_back(hdr);
 }
 
-int parse_headers(list<sip_header*>& hdrs, char** c)
+int parse_headers(list<sip_header*>& hdrs, char** c, char* end)
 {
     //
     // Header states
@@ -278,7 +278,7 @@ int parse_headers(list<sip_header*>& hdrs, char** c)
     char* begin = *c;
     auto_ptr<sip_header> hdr(new sip_header());
 
-    for(;**c;(*c)++){
+    for(;**c && (*c < end);(*c)++){
 
        switch(st){
 
diff --git a/core/sip/parse_header.h b/core/sip/parse_header.h
index 9810df8..eb990df 100644
--- a/core/sip/parse_header.h
+++ b/core/sip/parse_header.h
@@ -79,7 +79,7 @@ struct sip_header
     ~sip_header();
 };
 
-int parse_headers(list<sip_header*>& hdrs, char** c);
+int parse_headers(list<sip_header*>& hdrs, char** c, char* end);
 void free_headers(list<sip_header*>& hdrs);
 
 #endif
diff --git a/core/sip/sip_parser.cpp b/core/sip/sip_parser.cpp
index 66f89db..d4ab201 100644
--- a/core/sip/sip_parser.cpp
+++ b/core/sip/sip_parser.cpp
@@ -98,8 +98,6 @@ sip_msg::sip_msg()
 
 sip_msg::~sip_msg()
 {
-    // DBG("~sip_msg()\n");
-
     delete [] buf;
 
     list<sip_header*>::iterator it;
@@ -419,9 +417,9 @@ static int parse_first_line(sip_msg* msg, char** c)
     return UNEXPECTED_EOT;
 }
 
-int parse_headers(sip_msg* msg, char** c)
+int parse_headers(sip_msg* msg, char** c, char* end)
 {
-    int err = parse_headers(msg->hdrs,c);
+    int err = parse_headers(msg->hdrs,c,end);
     if(!err) {
        for(list<sip_header*>::iterator it = msg->hdrs.begin();
            it != msg->hdrs.end(); ++it) {
@@ -499,7 +497,7 @@ int parse_sip_msg(sip_msg* msg, char*& err_msg)
        return MALFORMED_FLINE;
     }
 
-    err = parse_headers(msg,&c);
+    err = parse_headers(msg,&c,c+msg->len);
 
     if(!err){
        msg->body.set(c,msg->len - (c - msg->buf));
diff --git a/core/sip/sip_parser.h b/core/sip/sip_parser.h
index cbf2eff..707b241 100644
--- a/core/sip/sip_parser.h
+++ b/core/sip/sip_parser.h
@@ -141,7 +141,7 @@ struct sip_msg
 };
 
 int parse_method(int* method, const char* beg, int len);
-int parse_headers(sip_msg* msg, char** c);
+int parse_headers(sip_msg* msg, char** c, char* end);
 int parse_sip_msg(sip_msg* msg, char*& err_msg);
 
 #define get_contact(msg) (msg->contacts.empty() ? NULL : 
(*msg->contacts.begin()))

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to