]> sjero.net Git - dccp2tcp/commitdiff
Multiple connection support segfault fixes
authorSamuel Jero <sj323707@ohio.edu>
Tue, 15 Nov 2011 22:12:41 +0000 (17:12 -0500)
committerSamuel Jero <sj323707@ohio.edu>
Tue, 15 Nov 2011 22:12:41 +0000 (17:12 -0500)
connections.c
dccp2tcp.c
dccp2tcp.h
encap.c

index 511692fc48ecca9cfc9049c5236c76888fae69cf..b5eb11287c71bfea62b3d9fdc7437badd177f47b 100644 (file)
@@ -9,7 +9,7 @@ Description: Functions for differentiating different DCCP connections.
 #include "dccp2tcp.h"
 
 /*Lookup a connection. If it doesn't exist, add a new connection and return it.*/
-int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host *fwd, struct host *rev){
+int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host **fwd, struct host **rev){
        struct connection *ptr;
 
        /*Empty list*/
@@ -17,8 +17,8 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
                if(add_connection(src_id, dest_id, src_port, dest_port)==NULL){
                        return 1;
                }
-               fwd=&chead->A;
-               rev=&chead->B;
+               *fwd=&chead->A;
+               *rev=&chead->B;
                return 0;
        }
 
@@ -26,13 +26,13 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        ptr=chead;
        while(ptr!=NULL){
                if(ptr->A.id==src_id && ptr->A.port==src_port && ptr->A.state!=CLOSE){
-                       fwd=&ptr->A;
-                       rev=&ptr->B;
+                       *fwd=&ptr->A;
+                       *rev=&ptr->B;
                        return 0;
                }
                if(ptr->B.id==src_id && ptr->B.port==src_port && ptr->B.state!=CLOSE){
-                       fwd=&ptr->B;
-                       rev=&ptr->A;
+                       *fwd=&ptr->B;
+                       *rev=&ptr->A;
                        return 0;
                }
                ptr=ptr->next;
@@ -43,8 +43,8 @@ int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, str
        if(ptr==NULL){
                return 1;
        }
-       fwd=&ptr->A;
-       rev=&ptr->B;
+       *fwd=&ptr->A;
+       *rev=&ptr->B;
        return 0;
 }
 
@@ -54,7 +54,7 @@ struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_por
        struct connection *prev;
 
        /*Allocate memory*/
-       if(chead){
+       if(chead==NULL){
                ptr=chead=malloc(sizeof(struct connection));
        }else{
                ptr=chead;
@@ -73,6 +73,7 @@ struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_por
 
        /*Initialize*/
        ptr->A.id=src_id;
+       ptr->A.port=src_port;
        ptr->A.state=INIT;
        ptr->B.id=dest_id;
        ptr->B.port=dest_port;
index eb913bf9dc23652d84b97774cda2cd5e61dd7a90..c8cc769d1068397c0810ee30f2688785adf7f9f6 100644 (file)
@@ -124,6 +124,7 @@ int main(int argc, char *argv[])
        }
 
        /*process packets*/
+       chead=NULL;
        u_char *user=(u_char*)out;
        pcap_loop(in, -1, handle_packet, user); 
        
@@ -198,6 +199,7 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        /*Safety checks*/
        if(!new || !old || !new->data || !old->data || !new->h || !old->h){
                dbgprintf(0,"Error:  Convert Packet Function given bad data!\n");
+               exit(1);
                return 0;
        }
        if(old->length < sizeof(struct dccp_hdr) || new->length < sizeof(struct dccp_hdr)){
@@ -215,11 +217,11 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        dbgprintf(2,"Sequence Number: %llu\n", (unsigned long long)(((unsigned long)ntohs(dccph->dccph_seq)<<32) + ntohl(dccphex->dccph_seq_low)));
 
        /*Get Hosts*/
-       if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, h1, h2)){
+       if(get_host(new->src_id, new->dest_id, dccph->dccph_sport, dccph->dccph_dport, &h1, &h2)){
                dbgprintf(0,"Error: Can't Get Hosts!\n");
                return 0;
        }
-       if(!h1 || !h2){
+       if(h1==NULL || h2==NULL){
                dbgprintf(0, "Error: Can't Get Hosts!\n");
                return 0;
        }
@@ -582,6 +584,11 @@ u_int32_t add_new_seq(struct host *seq, __be32 num, int size, enum dccp_pkt_type
                exit(1);
        }
        
+       if(seq->table==NULL){
+               dbgprintf(1, "Warning: Connection initialization incorrect\n");
+               return 0;
+       }
+
        /*account for missing packets*/
        while(seq->table[seq->cur].old +1 < num && seq->table[seq->cur].old +1 > 0){
                prev=seq->cur;
index 4b556cfcc979eb9ca39dff29b42cc71f803094e6..2a1dbfa18458f2f8c71a3db423b07e975fb88cd3 100644 (file)
@@ -119,7 +119,7 @@ void dbgprintf(int level, const char *fmt, ...);
 int do_encap(int link, struct packet *new, const struct const_packet *old);
 
 /*Connection functions*/
-int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host *fwd, struct host *rev);
+int get_host(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port, struct host **fwd, struct host **rev);
 struct connection *add_connection(uint32_t src_id, uint32_t dest_id, int src_port, int dest_port);
 int update_state(struct host* hst, enum con_state st);
 
diff --git a/encap.c b/encap.c
index b932bda706b1b04fdf56d150f5437e4e7e474fa5..beafa6814466b57b5887e13e445f9cae730bdcc9 100644 (file)
--- a/encap.c
+++ b/encap.c
@@ -78,6 +78,8 @@ int ethernet_encap(struct packet *new, const struct const_packet *old)
                /*Select Next Protocol*/
                switch(ntohs(ethh->ether_type)){
                        case ETHERTYPE_IP:
+                                       nnew.h=new->h;
+                                       nold.h=old->h;
                                        if(!ipv4_encap(&nnew, &nold)){
                                                        return 0;
                                        }
@@ -132,6 +134,8 @@ int ipv4_encap(struct packet *new, const struct const_packet *old)
                switch(iph->protocol){
                        case 0x21:
                                        /*DCCP*/
+                                       nnew.h=new->h;
+                                       nold.h=old->h;
                                        nnew.src_id=iph->saddr;
                                        nnew.dest_id=iph->daddr;
                                        if(!convert_packet(&nnew, &nold)){
@@ -200,6 +204,8 @@ int linux_cooked_encap(struct packet *new, const struct const_packet *old)
        /*Select Next Protocol*/
        switch(ntohs(slh->sll_protocol)){
                case ETHERTYPE_IP:
+                               nnew.h=new->h;
+                               nold.h=old->h;
                                if(!ipv4_encap(&nnew, &nold)){
                                                return 0;
                                }