Why Rtlcopymemory Failed

All, I was trying to use RtlCopyMemory to duplicate a structure instance, But seems it didn't successfully copy the instance before the callback returns. I didn't know if I missed something, Please help to review the below code. Thanks.

#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))

typedef struct _FLT_RELATED_OBJECTS {

    USHORT CONST Size;
    USHORT CONST TransactionContext;            //TxF mini-version
    PFLT_FILTER CONST Filter;
    PFLT_VOLUME CONST Volume;
    PFLT_INSTANCE CONST Instance;
    PFILE_OBJECT CONST FileObject;
    PKTRANSACTION CONST Transaction;

} FLT_RELATED_OBJECTS, *PFLT_RELATED_OBJECTS;

FLT_POSTOP_CALLBACK_STATUS
CreateBackUpFile_WhenPostCreatedCallback (
    _Inout_ PFLT_CALLBACK_DATA Data,
    _In_ PCFLT_RELATED_OBJECTS FltObjects,
    _In_ PVOID CompletionContext,
    _In_ FLT_POST_OPERATION_FLAGS Flags
    )
{
   PFLT_RELATED_OBJECTS copiedRelatedObj;
   ...
   RtlZeroMemory(&copiedRelatedObj, FltObjects->Size);
   KdBreakPoint();
   RtlCopyMemory(&copiedRelatedObj,FltObjects,FltObjects->Size);
   DbgPrint("The file name in the FltObjects is : %s\n",FltObjects->FileObject->FileName);
   DbgPrint("The file name in the Duplicated FltObjects is : %s\n",copiedRelatedObj->FileObject->FileName);
   ...
}

2 Answers

RtlZeroMemory requires pointer to a memory block as its first argument. But you give it pointer to pointer ( as PFLT_RELATED_OBJECTS is already a pointer ). Use

FLT_RELATED_OBJECTS copiedRelatedObj;
2
   PFLT_RELATED_OBJECTS copiedRelatedObj;

The copiedRelatedObj variable is a pointer. It is not initialized. Yell a bit invisible Microsoft C programmers for that dreadful habit of declaring pointer types. Then remove the P. Fix:

   FLT_RELATED_OBJECTS copiedRelatedObj;
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest