ProbeForRead Issue

Note : My first query not posted still waiting so, I sending it again.

Hi all,

I m writing minifilter driver and new in it , using minispy sample; In preoperation Callback function to handle garbage buffer value (becuase sometime it is crashed) I used “ProbeForRead”,

Code:

PUNICODE_STIRNG nameToUse ;
if (FltObjects->FileObject != NULL) {

status = FltGetFileNameInformation( Data,
FLT_FILE_NAME_NORMALIZED |
WinFLData.NameQueryMethod,
&nameInfo );

} else{

status = STATUS_UNSUCCESSFUL;
}

if (NT_SUCCESS( status )) {

nameToUse = &nameInfo->Name;

if (FlagOn( WinFLData.DebugFlags, WINFL_DEBUG_PARSE_NAMES )) {

status = FltParseFileNameInformation( nameInfo );
ASSERT(NT_SUCCESS(status));
}

} else {

RtlInitUnicodeString( &defaultName, L"" );
nameToUse = &defaultName;
}

if (NULL != nameInfo) {

FltReleaseFileNameInformation( nameInfo );
}
try
{
ProbeForRead(nameToUse,sizeof(UNICODE_STRING),1);
DbgPrint(“%ws”,nameToUse->Buffer); // Sometime is crashed when ProbeForRead not

}
except(EXCEPTION_EXECUTE_HANDLER)
{

}

Issue: everytime ProbeForRead throwing an exception and I could see buffer print

Is there any way to handle plz help me

It makes no sense to use ProbeForRead here as this is not a usermode buffer.
Obviously after calling FltReleaseFileNameInformation nameToUse points to
freed memory.

//Daniel

wrote in message news:xxxxx@ntfsd…
> Note : My first query not posted still waiting so, I sending it again.
>
> Hi all,
>
> I m writing minifilter driver and new in it , using minispy sample; In
> preoperation Callback function to handle garbage buffer value (becuase
> sometime it is crashed) I used “ProbeForRead”,
>
> Code:
>
> PUNICODE_STIRNG nameToUse ;
> if (FltObjects->FileObject != NULL) {
>
> status = FltGetFileNameInformation( Data,
> FLT_FILE_NAME_NORMALIZED |
> WinFLData.NameQueryMethod,
> &nameInfo );
>
> } else{
>
> status = STATUS_UNSUCCESSFUL;
> }
>
>
> if (NT_SUCCESS( status )) {
>
> nameToUse = &nameInfo->Name;
>
> if (FlagOn( WinFLData.DebugFlags, WINFL_DEBUG_PARSE_NAMES )) {
>
> status = FltParseFileNameInformation( nameInfo );
> ASSERT(NT_SUCCESS(status));
> }
>
> } else {
>
>
> RtlInitUnicodeString( &defaultName, L"" );
> nameToUse = &defaultName;
> }
>
> if (NULL != nameInfo) {
>
> FltReleaseFileNameInformation( nameInfo );
> }
> try
> {
> ProbeForRead(nameToUse,sizeof(UNICODE_STRING),1);
> DbgPrint(“%ws”,nameToUse->Buffer); // Sometime is crashed when
> ProbeForRead not
>
> }
> except(EXCEPTION_EXECUTE_HANDLER)
> {
>
>
> }
>
>
> Issue: everytime ProbeForRead throwing an exception and I could see buffer
> print
>
> Is there any way to handle plz help me
>

Daniel,

Actuall my issue is that I want to handle, extra garbage character those I getting in nameToUse buffer, when Print in DbgView then I seen this garbage character.

Thanks

One problem is is that nameToUse points to freed memory, so you should
expect garbage in there. Another problem is that you are printing the buffer
of a unicode string which is a counted string and not normally terminated by
a NULL character.

//Daniel

wrote in message news:xxxxx@ntfsd…
> Daniel,
>
> Actuall my issue is that I want to handle, extra garbage character those I
> getting in nameToUse buffer, when Print in DbgView then I seen this
> garbage character.
>
>
> Thanks
>

On Mon, 9 Mar 2009, xxxxx@yahoo.com wrote:

You should print the unicode string like this instead:

DbgPrint(“%.*S”, nameToUse->Length / 2, nameToUse->Buffer);

I m writing minifilter driver and new in it , using minispy sample; In preoperation Callback function to handle garbage buffer value (becuase sometime it is crashed) I used “ProbeForRead”,

Code:

PUNICODE_STIRNG nameToUse ;
if (FltObjects->FileObject != NULL) {

status = FltGetFileNameInformation( Data,
FLT_FILE_NAME_NORMALIZED |
WinFLData.NameQueryMethod,
&nameInfo );

} else{

status = STATUS_UNSUCCESSFUL;
}

if (NT_SUCCESS( status )) {

nameToUse = &nameInfo->Name;

if (FlagOn( WinFLData.DebugFlags, WINFL_DEBUG_PARSE_NAMES )) {

status = FltParseFileNameInformation( nameInfo );
ASSERT(NT_SUCCESS(status));
}

} else {

RtlInitUnicodeString( &defaultName, L"" );
> nameToUse = &defaultName;
> }
>
> if (NULL != nameInfo) {
>
> FltReleaseFileNameInformation( nameInfo );
> }
> try
> {
> ProbeForRead(nameToUse,sizeof(UNICODE_STRING),1);
> DbgPrint(“%ws”,nameToUse->Buffer); // Sometime is crashed when ProbeForRead not
>
> }
> except(EXCEPTION_EXECUTE_HANDLER)
> {
>
>
> }
>
>
> Issue: everytime ProbeForRead throwing an exception and I could see buffer print
>
> Is there any way to handle plz help me
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

Bo Brantén wrote:

On Mon, 9 Mar 2009, xxxxx@yahoo.com wrote:

You should print the unicode string like this instead:

DbgPrint(“%.*S”, nameToUse->Length / 2, nameToUse->Buffer);

What about the standard way use unicode strings in a DbgPrint statement?

DbgPrint(“Here is the string %wZ\n”, nameToUse);

And as Daniel said, don’t release the name information until AFTER you
have printed or used it.

Pete

> I m writing minifilter driver and new in it , using minispy sample; In
> preoperation Callback function to handle garbage buffer value
> (becuase sometime it is crashed) I used “ProbeForRead”,
>
> Code:
>
> PUNICODE_STIRNG nameToUse ;
> if (FltObjects->FileObject != NULL) {
>
> status = FltGetFileNameInformation( Data,
> FLT_FILE_NAME_NORMALIZED |
> WinFLData.NameQueryMethod,
> &nameInfo );
>
> } else{
>
> status = STATUS_UNSUCCESSFUL;
> }
>
>
> if (NT_SUCCESS( status )) {
>
> nameToUse = &nameInfo->Name;
>
> if (FlagOn( WinFLData.DebugFlags, WINFL_DEBUG_PARSE_NAMES )) {
>
> status = FltParseFileNameInformation( nameInfo );
> ASSERT(NT_SUCCESS(status));
> }
>
> } else {
>
>
> RtlInitUnicodeString( &defaultName, L"" );
>> nameToUse = &defaultName;
>> }
>>
>> if (NULL != nameInfo) {
>>
>> FltReleaseFileNameInformation( nameInfo );
>> }
>> try
>> {
>> ProbeForRead(nameToUse,sizeof(UNICODE_STRING),1);
>> DbgPrint(“%ws”,nameToUse->Buffer); // Sometime is crashed when
>> ProbeForRead not
>>
>> }
>> except(EXCEPTION_EXECUTE_HANDLER)
>> {
>>
>>
>> }
>>
>>
>> Issue: everytime ProbeForRead throwing an exception and I could see
>> buffer print
>>
>> Is there any way to handle plz help me
>>
>> —
>> NTFSD is sponsored by OSR
>>
>> For our schedule of debugging and file system seminars
>> (including our new fs mini-filter seminar) visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer


Kernel Drivers
Windows File System and Device Driver Consulting
www.KernelDrivers.com
866.263.9295

> DbgPrint(“%.*S”, nameToUse->Length / 2, nameToUse->Buffer);

or as

DbgPrint(“%wZ”,nameToUse);


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Maybe it should be DbgPrint(“%wZ”, &nameToUse); since I didn’t see if that
variable was a PUNICODE_STRING. I could be a stack based UNICODE_STRING.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> DbgPrint(“%.*S”, nameToUse->Length / 2, nameToUse->Buffer);

or as

DbgPrint(“%wZ”,nameToUse);


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

He uses “nameToUse->”, not “nameToUse.”


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“David Craig” wrote in message news:xxxxx@ntfsd…
> Maybe it should be DbgPrint(“%wZ”, &nameToUse); since I didn’t see if that
> variable was a PUNICODE_STRING. I could be a stack based UNICODE_STRING.
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntfsd…
>> DbgPrint(“%.*S”, nameToUse->Length / 2, nameToUse->Buffer);
>
> or as
>
> DbgPrint(“%wZ”,nameToUse);
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>
>