I’m having a weird issue with this code:

static char *
reassemble_tcp_message(struct my_tcp_split_packet *msp1)
{
    VLOG_ERR("tot splits: %d, sizepayload %u", msp1[0].tot_splits, 
msp1[0].sizeofpayload);
    char *temp_payload_reass = malloc((char *) * msp1[0].sizeofpayload + 1);
    temp_payload_reass[0] = '\0';

    for(int i=0; i < msp1[0].tot_splits; i++)
    {
        uint32_t size_split = tcp_payload_length(msp1[i].packet);
        int strlen_split = strlen((char *) 
dp_packet_get_tcp_payload(msp1[i].packet));
        VLOG_ERR("strlen of split being concatted %d, size_split: %u", 
strlen_split, size_split);
        strncat(temp_payload_reass, (char *) 
dp_packet_get_tcp_payload(msp1[i].packet), (int) size_split);

    }
    return temp_payload_reass;
}

Basically, I have split a tcp packet payload into multiple random parts, and 
inserted each split in a different packet, and I need to reassemble the 
payloads to recreate the original payload. However, when tls packets are 
involved this function doesn’t work, while with regular http traffic it 
performs its magic.

In msp1 I have an array of structs containing all the splits which are needed 
to reassemble the original payload. I also have access to the original payload  
size and the total number of split packets.
Size_split always contains the right payload length, however when I do strncat, 
the resulting string’s length doesn’t equal size_split (that part of the code 
was omitted but I tested it).
Another weird thing that happens is that the code sometimes works even in the 
tls packet cases, and this happens when strlen_split == size_split, that is 
when the resulting string’s length equals  size_split but it happens in rare 
occasions.

Maybe being a C novice I’ve made some stupid mistake, I also do free 
temp_payload_reass later on in the code

Any help is appreciated!

Luca
_______________________________________________
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

Reply via email to