- removed -fPIC -DPIC from the Makefile (see comments)
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 6 Dec 2001 20:43:05 +0000 (20:43 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Thu, 6 Dec 2001 20:43:05 +0000 (20:43 +0000)
- fixed a memory leak in do_action/forward uri
- fixed parse_cseq (still buggy, but a little bit better :))
- added error if header name does not end on 1 line (parse_hname)
- fixed mem. leak in parse_via (if bad param)

Makefile
action.c
msg_parser.c
parse_hname.c
parse_via.c
receive.c

index 7138c4e..2c77710 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ NAME=ser
 #                  twice, trying to free a pointer alloc'ed with a different
 #                  malloc etc.)
 DEFS=-DTHREAD -DNOCR -DMACROEATER -DDNS_IP_HACK  -DSHM_MEM \
-        -DPKG_MALLOC #-DDBG_QM_MALLOC -DNO_DEBUG
+        -DPKG_MALLOC -DDBG_QM_MALLOC #-DNO_DEBUG
 # -DUSE_SHM_MEM
 #-DNO_DEBUG 
 #-DPKG_MALLOC
@@ -43,8 +43,8 @@ DEFS=-DTHREAD -DNOCR -DMACROEATER -DDNS_IP_HACK  -DSHM_MEM \
 #-DNO_LOG
 
 PROFILE=  # -pg #set this if you want profiling
-mode = debug
-#mode = release
+#mode = debug
+mode = release
 
 # platform dependent settings
 
index 66d8ba9..c32bd32 100644 (file)
--- a/action.c
+++ b/action.c
@@ -79,8 +79,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                                                                                        "forward: bad port in "
                                                                                                        "uri: <%s>\n", uri.port);
                                                                                        ret=E_UNSPEC;
-                                                                                       free_uri(&uri);
-                                                                                       goto skip;
+                                                                                       goto error_fwd_uri;
                                                                                }
                                                                        }else port=SIP_PORT;
                                                                        break;
@@ -90,11 +89,17 @@ int do_action(struct action* a, struct sip_msg* msg)
                                        default:
                                                        LOG(L_CRIT, "BUG: do_action bad forward 2nd"
                                                                                " param type (%d)\n", a->p2_type);
-                                                       free_uri(&uri);
-                                                       goto skip;
+                                                       ret=E_UNSPEC;
+                                                       goto error_fwd_uri;
                                }
                                /* create a temporary proxy*/
                                p=mk_proxy(uri.host.s, port);
+                               if (p==0){
+                                       LOG(L_ERR, "ERROR:  bad host name in uri,"
+                                                       " dropping packet\n");
+                                       ret=E_BAD_ADDRESS;
+                                       goto error_fwd_uri;
+                               }
                                ret=forward_request(msg, p);
                                free_uri(&uri);
                                free_proxy(p); /* frees only p content, not p itself */
@@ -362,6 +367,9 @@ error_uri:
        free_uri(&uri);
        if (new_uri) free(new_uri);
        return E_UNSPEC;
+error_fwd_uri:
+       free_uri(&uri);
+       return ret;
 }
 
 
index 19c33af..c141c15 100644 (file)
@@ -315,7 +315,7 @@ char* parse_hostport(char* buf, str* host, short int* port)
 /*BUGGY*/
 char * parse_cseq(char *buf, char* end, struct cseq_body* cb)
 {
-       char *t;
+       char *t, *m, *m_end;
        char c;
 
        cb->error=PARSE_ERROR;
@@ -325,17 +325,24 @@ char * parse_cseq(char *buf, char* end, struct cseq_body* cb)
        cb->number.s=t;
        t=eat_token_end(t, end);
        if (t>=end) goto error;
+       m=eat_space_end(t, end);
+       m_end=eat_token_end(m, end);
        *t=0; /*null terminate it*/
        cb->number.len=t-cb->number.s;
-       t++;
-       t=eat_space_end(t, end);
-       if (t>=end) goto error;
-       cb->method.s=t;
-       t=eat_token_end(t, end);
-       if (t>=end) goto error;
+       DBG("parse_cseq: found number %s\n", cb->number.s);
+       
+       if (m_end>=end) goto error;
+       if (m_end==m){
+               /* null method*/
+               LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
+               goto error;
+       }
+       cb->method.s=m;
+       t=m_end;
        c=*t;
        *t=0; /*null terminate it*/
        cb->method.len=t-cb->method.s;
+       DBG("parse_cseq: found method %s\n", cb->method.s);
        t++;
        /*check if the header ends here*/
        if (c=='\n') goto check_continue;
@@ -513,6 +520,7 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
        
        return ret;
 error:
+       free_uri(uri);
        return ret;
 }
 
@@ -542,11 +550,11 @@ int parse_headers(struct sip_msg* msg, int flags)
        DBG("parse_headers: flags=%d\n", flags);
        while( tmp<end && (flags & msg->parsed_flag) != flags){
                hf=pkg_malloc(sizeof(struct hdr_field));
-               memset(hf,0, sizeof(struct hdr_field));
                if (hf==0){
                        LOG(L_ERR, "ERROR:parse_headers: memory allocation error\n");
                        goto error;
                }
+               memset(hf,0, sizeof(struct hdr_field));
                hf->type=HDR_ERROR;
                rest=get_hdr_field(tmp, msg->buf+msg->len, hf);
                switch (hf->type){
index 2c92811..0cf8f2f 100644 (file)
@@ -488,6 +488,11 @@ char* parse_hname(char* p, char* end, struct hdr_field* hdr)
                                                                goto error;
                                                }
                                                break;
+                                               
+                       case '\n':
+                       case '\r': /*not allowed in hname*/
+                                               goto error;
+                       
                        default:
                                        switch(state){
                                                case INITIAL:
index 84e352b..cfdb015 100644 (file)
@@ -1603,6 +1603,7 @@ main_via:
                                                                state=saved_state;
                                                                goto endofheader;
                                                        case PARAM_ERROR:
+                                                               pkg_free(param);
                                                                goto error;
                                                        default:
                                                                LOG(L_ERR, "ERROR: parse_via after"
index cac7c54..2c7e7e1 100644 (file)
--- a/receive.c
+++ b/receive.c
@@ -77,6 +77,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
                                        "error while trying script\n");
                        goto error;
                }
+               DBG("succesfully ran routing scripts...\n");
 #ifdef STATS
                /* jku -- update request statistics  */
                else update_received_request(msg->first_line.u.request.method_value );
@@ -115,6 +116,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 skip:
        DBG("skip:...\n");
 */
+       DBG("receive_msg: cleaning up\n");
        free_sip_msg(msg);
        pkg_free(msg);
 #ifdef STATS