none
FwpsCopyStreamDataToBuffer0 adding junk data RRS feed

  • Question

  • Hey,

    I am having a problem copying the data at the stream layer into a buffer. When I send a message I am receiving extra non sense characters that I am unsure why they are showing up. For example if I send the message "hello there" I receive the message BUFFER: hello thereåí„ with "åí„ " being the added non sense characters after calling FwpsCopyStreamDataToBuffer0. Below is the code I am using inside of the Stream callout. Does anyone know where I am going wrong with this and getting the extra characters? Thank you!

    {
        FWPS_STREAM_CALLOUT_IO_PACKET* ioPacket = (FWPS_STREAM_CALLOUT_IO_PACKET*)layerData;
        FWPS_STREAM_DATA* streamData;
       
        ioPacket = (FWPS_STREAM_CALLOUT_IO_PACKET*)layerData;
        if(ioPacket == NULL)
        {
            DoTraceMessage(TRACE_STATE, "NULL Value: ioPacket");
            return;
        }

        streamData = ioPacket->streamData;
        if(streamData == NULL)
        {
            DoTraceMessage(TRACE_STATE, "NULL Value: streamData");
            return;
        }
       
        // Create a buffer to get the information
        BYTE* buff = (BYTE*)ExAllocatePoolWithTag(NonPagedPool, streamData->dataLength, 'OjGF');
        if(!buff)
        {
            DoTraceMessage(TRACE_STATE, "Allocation Failed: buff");
            return;
        }
        RtlZeroMemory(buff, streamData->dataLength);
       
        // Copy information to a buffer
        SIZE_T bytesCopied = 0;
        FwpsCopyStreamDataToBuffer0(streamData, buff, streamData->dataLength, &bytesCopied);
       
        DoTraceMessage(TRACE_STATE, "BUFFER: %s", (char*)buff);
       
        ExFreePoolWithTag(buff, 'OjGF');
    }

     

    Monday, June 20, 2011 7:16 PM

All replies

  • Did you verify what the actual original buffer was? What is the streamData->dataLength value?

     

     

     


    Dusty Harper [MSFT]
    Microsoft Corporation
    ------------------------------------------------------------
    This posting is provided "AS IS", with NO warranties and confers NO rights
    ------------------------------------------------------------
    Wednesday, June 22, 2011 7:22 PM
    Moderator
  • I set up a cmd prompt to send a message to myself in another command prompt. In the first cmd prompt I send "hello there" and in the second cmd prompt the message would appear as "hello there". Inside of the callout streamData->dataLength has the value 12. "hello there" is 11 characters. I believe the 12th character is for a \n. I use the CopyStreamDataToBuffer function and use DoTraceMessage(TRACE_STATE, "BUFFER: %s", (char*)buff); to print the message. This printed 4 extra nonsense characters. This only happens sometimes. Sometimes it will print the correct message "hello there". Thats why im confused as to why this is happening I dont get where it is even getting the extra 4 characters from because I allocate the buffer with BYTE* buff = (BYTE*)ExAllocatePoolWithTag(NonPagedPool, streamData->dataLength, 'OjGF'); and that is only allocating room for 12 characters unless the allocation is wrong. Do you have any other ideas as to why thats happening?
    Wednesday, June 22, 2011 8:27 PM