Unicode strings memory allocation problem.

Dear All,

I am developing a filter driver and filtering the request coming from user
mode for Windows 2000 operating system

I am encountering an unusual behaviour in my driver . I am getting file name
from the fileobject and then I make two similiar unicode strings having full
path names from this filename. But at some times one unicode strings get
fullpath name but the other one gets only some part of it. Although the code
for both is the same.Below is detailed explaination:

Step 1) I am getting file name from fileobject using following code"
///////
irpStack = IoGetCurrentIrpStackLocation( Irp );
fileObject = irpStack->FileObject;
fileName = &fileObject->FileName;
devExt = DeviceObject->DeviceExtension;
///////

Step2) The I am making two unicode strings having complete filepath from the
given file name using, the fullFileNameWrt and tempA.

The tempA unicode string path contains fullpath name in CAPITAL Letters.
/////////////////////////////
fullFileNameWrt.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
fullFileNameWrt.MaximumLength,‘2leM’);
if(NULL == fullFileNameWrt.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);

tempA.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
tempA.MaximumLength,‘2leD’);

if(NULL == tempA.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
if(fullFileNameWrt.Buffer) {
ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
}
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&tempA, fileName);

tempA.Buffer[tempA.Length] = L’\0’;
tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
_wcsupr(tempA.Buffer);

DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
////////////////////////

But at most of the times while filtering , I am not getting the complete
filepath in fullFileNameWrt although I am gettings fullfilepath in

tempA unicode string

JAI fullFileNameWrt: c:\Docum
JAI tempA: C:\DOCUMENTS AND SETTINGS\NEW11\APPLICATION
DATA\MACROMEDIA\FLASHPLAYER\

MACROMEDIA.COM\FLASHPLAYER\SYS\SETTIGS.SYX!

////////
To know more I have added ! mark to check the end of filepath in my
Dbgprints. But There is no ! mark found in fullFileNameWrt. (as shown in the
above output)

Can some body please tell what the problem exactly is ?? Is this happening
because the file name is tooo big ??? Please help.

Regards,
Rohit

If I’m not wrong try the following code… just added code to specify the length…

=========================================================

fullFileNameWrt.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
fullFileNameWrt.MaximumLength,‘2leM’);
if(NULL == fullFileNameWrt.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);

//Added ===>

fullFileNameWrt.Length = wcslen(fullFileNameWrt.Buffer) * sizeof(WCHAR);
fullFileNameWrt.Buffer[fullFileNameWrt.Length] = L’\0’;

//<===

tempA.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
tempA.MaximumLength,‘2leD’);

if(NULL == tempA.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
if(fullFileNameWrt.Buffer) {
ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
}
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&tempA, fileName);

tempA.Buffer[tempA.Length] = L’\0’;
tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
_wcsupr(tempA.Buffer);

DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);

==================================

cheers
K.Raju…

=================
-----Original Message-----
From: Rohit Dhamija [mailto:xxxxx@divassoftware.com]
Sent: Friday, May 28, 2004 11:00 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Unicode strings memory allocation problem.

Dear All,

I am developing a filter driver and filtering the request coming from user
mode for Windows 2000 operating system

I am encountering an unusual behaviour in my driver . I am getting file name
from the fileobject and then I make two similiar unicode strings having full
path names from this filename. But at some times one unicode strings get
fullpath name but the other one gets only some part of it. Although the code
for both is the same.Below is detailed explaination:

Step 1) I am getting file name from fileobject using following code"
///////
irpStack = IoGetCurrentIrpStackLocation( Irp );
fileObject = irpStack->FileObject;
fileName = &fileObject->FileName;
devExt = DeviceObject->DeviceExtension;
///////

Step2) The I am making two unicode strings having complete filepath from the
given file name using, the fullFileNameWrt and tempA.

The tempA unicode string path contains fullpath name in CAPITAL Letters.
/////////////////////////////
fullFileNameWrt.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
fullFileNameWrt.MaximumLength,‘2leM’);
if(NULL == fullFileNameWrt.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);

tempA.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
tempA.MaximumLength,‘2leD’);

if(NULL == tempA.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
if(fullFileNameWrt.Buffer) {
ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
}
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&tempA, fileName);

tempA.Buffer[tempA.Length] = L’\0’;
tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
_wcsupr(tempA.Buffer);

DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
////////////////////////

But at most of the times while filtering , I am not getting the complete
filepath in fullFileNameWrt although I am gettings fullfilepath in

tempA unicode string

JAI fullFileNameWrt: c:\Docum
JAI tempA: C:\DOCUMENTS AND SETTINGS\NEW11\APPLICATION
DATA\MACROMEDIA\FLASHPLAYER\

MACROMEDIA.COM\FLASHPLAYER\SYS\SETTIGS.SYX!

////////
To know more I have added ! mark to check the end of filepath in my
Dbgprints. But There is no ! mark found in fullFileNameWrt. (as shown in the
above output)

Can some body please tell what the problem exactly is ?? Is this happening
because the file name is tooo big ??? Please help.

Regards,
Rohit


Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@inquesttechnologies.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks a lot. I am in process of testing the code.
Can you please tell me what is the purpose of using
RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
in this situation ?
Regards
Rohit

“Krishnama Raju” wrote in message
news:xxxxx@ntfsd…
If I’m not wrong try the following code… just added code to specify the
length…

=========================================================

fullFileNameWrt.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
fullFileNameWrt.MaximumLength,‘2leM’);
if(NULL == fullFileNameWrt.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);

//Added ===>

fullFileNameWrt.Length = wcslen(fullFileNameWrt.Buffer) * sizeof(WCHAR);
fullFileNameWrt.Buffer[fullFileNameWrt.Length] = L’\0’;

//<===

tempA.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
tempA.MaximumLength,‘2leD’);

if(NULL == tempA.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
if(fullFileNameWrt.Buffer) {
ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
}
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&tempA, fileName);

tempA.Buffer[tempA.Length] = L’\0’;
tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
_wcsupr(tempA.Buffer);

DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);

==================================

cheers
K.Raju…

=================
-----Original Message-----
From: Rohit Dhamija [mailto:xxxxx@divassoftware.com]
Sent: Friday, May 28, 2004 11:00 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Unicode strings memory allocation problem.

Dear All,

I am developing a filter driver and filtering the request coming from user
mode for Windows 2000 operating system

I am encountering an unusual behaviour in my driver . I am getting file name
from the fileobject and then I make two similiar unicode strings having full
path names from this filename. But at some times one unicode strings get
fullpath name but the other one gets only some part of it. Although the code
for both is the same.Below is detailed explaination:

Step 1) I am getting file name from fileobject using following code"
///////
irpStack = IoGetCurrentIrpStackLocation( Irp );
fileObject = irpStack->FileObject;
fileName = &fileObject->FileName;
devExt = DeviceObject->DeviceExtension;
///////

Step2) The I am making two unicode strings having complete filepath from the
given file name using, the fullFileNameWrt and tempA.

The tempA unicode string path contains fullpath name in CAPITAL Letters.
/////////////////////////////
fullFileNameWrt.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
fullFileNameWrt.MaximumLength,‘2leM’);
if(NULL == fullFileNameWrt.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);

tempA.MaximumLength = fileName->MaximumLength +
devExt->DeviceName.MaximumLength + 2;
tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
tempA.MaximumLength,‘2leD’);

if(NULL == tempA.Buffer) {
DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
if(fullFileNameWrt.Buffer) {
ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
}
status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
RtlAppendUnicodeStringToString(&tempA, fileName);

tempA.Buffer[tempA.Length] = L’\0’;
tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
_wcsupr(tempA.Buffer);

DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
////////////////////////

But at most of the times while filtering , I am not getting the complete
filepath in fullFileNameWrt although I am gettings fullfilepath in

tempA unicode string

JAI fullFileNameWrt: c:\Docum
JAI tempA: C:\DOCUMENTS AND SETTINGS\NEW11\APPLICATION
DATA\MACROMEDIA\FLASHPLAYER<br>
MACROMEDIA.COM\FLASHPLAYER\SYS\SETTIGS.SYX!

////////
To know more I have added ! mark to check the end of filepath in my
Dbgprints. But There is no ! mark found in fullFileNameWrt. (as shown in the
above output)

Can some body please tell what the problem exactly is ?? Is this happening
because the file name is tooo big ??? Please help.

Regards,
Rohit


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@inquesttechnologies.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

No need at all :slight_smile:

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Rohit Dhamija”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Friday, May 28, 2004 10:53 AM
Subject: Re:[ntfsd] Unicode strings memory allocation problem.

> Thanks a lot. I am in process of testing the code.
> Can you please tell me what is the purpose of using
> RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
> in this situation ?
> Regards
> Rohit
>
> “Krishnama Raju” wrote in message
> news:xxxxx@ntfsd…
> If I’m not wrong try the following code… just added code to specify the
> length…
>
> =========================================================
>
> fullFileNameWrt.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> fullFileNameWrt.MaximumLength,‘2leM’);
> if(NULL == fullFileNameWrt.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
> RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
> RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);
>
> //Added ===>
>
> fullFileNameWrt.Length = wcslen(fullFileNameWrt.Buffer) * sizeof(WCHAR);
> fullFileNameWrt.Buffer[fullFileNameWrt.Length] = L’\0’;
>
> //<===
>
>
> tempA.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> tempA.MaximumLength,‘2leD’);
>
> if(NULL == tempA.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> if(fullFileNameWrt.Buffer) {
> ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
> }
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
>
> RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&tempA, fileName);
>
> tempA.Buffer[tempA.Length] = L’\0’;
> tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
> _wcsupr(tempA.Buffer);
>
>
> DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
> DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
>
>
> ==================================
>
> cheers
> K.Raju…
>
> =================
> -----Original Message-----
> From: Rohit Dhamija [mailto:xxxxx@divassoftware.com]
> Sent: Friday, May 28, 2004 11:00 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Unicode strings memory allocation problem.
>
>
> Dear All,
>
> I am developing a filter driver and filtering the request coming from user
> mode for Windows 2000 operating system
>
> I am encountering an unusual behaviour in my driver . I am getting file name
> from the fileobject and then I make two similiar unicode strings having full
> path names from this filename. But at some times one unicode strings get
> fullpath name but the other one gets only some part of it. Although the code
> for both is the same.Below is detailed explaination:
>
> Step 1) I am getting file name from fileobject using following code"
> ///////
> irpStack = IoGetCurrentIrpStackLocation( Irp );
> fileObject = irpStack->FileObject;
> fileName = &fileObject->FileName;
> devExt = DeviceObject->DeviceExtension;
> ///////
>
> Step2) The I am making two unicode strings having complete filepath from the
> given file name using, the fullFileNameWrt and tempA.
>
> The tempA unicode string path contains fullpath name in CAPITAL Letters.
> /////////////////////////////
> fullFileNameWrt.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> fullFileNameWrt.MaximumLength,‘2leM’);
> if(NULL == fullFileNameWrt.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
> RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);
>
> tempA.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> tempA.MaximumLength,‘2leD’);
>
> if(NULL == tempA.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> if(fullFileNameWrt.Buffer) {
> ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
> }
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
>
> RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&tempA, fileName);
>
> tempA.Buffer[tempA.Length] = L’\0’;
> tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
> _wcsupr(tempA.Buffer);
>
>
> DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
> DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
> ////////////////////////
>
> But at most of the times while filtering , I am not getting the complete
> filepath in fullFileNameWrt although I am gettings fullfilepath in
>
> tempA unicode string
>
> JAI fullFileNameWrt: c:\Docum
> JAI tempA: C:\DOCUMENTS AND SETTINGS\NEW11\APPLICATION
> DATA\MACROMEDIA\FLASHPLAYER<br>>
> MACROMEDIA.COM\FLASHPLAYER\SYS\SETTIGS.SYX!
>
> ////////
> To know more I have added ! mark to check the end of filepath in my
> Dbgprints. But There is no ! mark found in fullFileNameWrt. (as shown in the
> above output)
>
>
> Can some body please tell what the problem exactly is ?? Is this happening
> because the file name is tooo big ??? Please help.
>
> Regards,
> Rohit
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@inquesttechnologies.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

…No need , incase you are using the variable only for this …but you need to do this if you had used the same variable for some other purpose above this part of code…

RtlZeroMemory fills the block with zeros hence it clears if at all any junk value exists.

– Cheers
K.Raju

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Friday, May 28, 2004 12:36 PM
To: Windows File Systems Devs Interest List
Subject: Re: Re:[ntfsd] Unicode strings memory allocation problem.

No need at all :slight_smile:

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Rohit Dhamija”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Friday, May 28, 2004 10:53 AM
Subject: Re:[ntfsd] Unicode strings memory allocation problem.

> Thanks a lot. I am in process of testing the code.
> Can you please tell me what is the purpose of using
> RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
> in this situation ?
> Regards
> Rohit
>
> “Krishnama Raju” wrote in message
> news:xxxxx@ntfsd…
> If I’m not wrong try the following code… just added code to specify the
> length…
>
> =========================================================
>
> fullFileNameWrt.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> fullFileNameWrt.MaximumLength,‘2leM’);
> if(NULL == fullFileNameWrt.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
> RtlZeroMemory(&fullFileNameWrt,sizeof(UNICODE_STRING));
> RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);
>
> //Added ===>
>
> fullFileNameWrt.Length = wcslen(fullFileNameWrt.Buffer) * sizeof(WCHAR);
> fullFileNameWrt.Buffer[fullFileNameWrt.Length] = L’\0’;
>
> //<===
>
>
> tempA.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> tempA.MaximumLength,‘2leD’);
>
> if(NULL == tempA.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> if(fullFileNameWrt.Buffer) {
> ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
> }
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
>
> RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&tempA, fileName);
>
> tempA.Buffer[tempA.Length] = L’\0’;
> tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
> _wcsupr(tempA.Buffer);
>
>
> DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
> DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
>
>
> ==================================
>
> cheers
> K.Raju…
>
> =================
> -----Original Message-----
> From: Rohit Dhamija [mailto:xxxxx@divassoftware.com]
> Sent: Friday, May 28, 2004 11:00 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Unicode strings memory allocation problem.
>
>
> Dear All,
>
> I am developing a filter driver and filtering the request coming from user
> mode for Windows 2000 operating system
>
> I am encountering an unusual behaviour in my driver . I am getting file name
> from the fileobject and then I make two similiar unicode strings having full
> path names from this filename. But at some times one unicode strings get
> fullpath name but the other one gets only some part of it. Although the code
> for both is the same.Below is detailed explaination:
>
> Step 1) I am getting file name from fileobject using following code"
> ///////
> irpStack = IoGetCurrentIrpStackLocation( Irp );
> fileObject = irpStack->FileObject;
> fileName = &fileObject->FileName;
> devExt = DeviceObject->DeviceExtension;
> ///////
>
> Step2) The I am making two unicode strings having complete filepath from the
> given file name using, the fullFileNameWrt and tempA.
>
> The tempA unicode string path contains fullpath name in CAPITAL Letters.
> /////////////////////////////
> fullFileNameWrt.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> fullFileNameWrt.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> fullFileNameWrt.MaximumLength,‘2leM’);
> if(NULL == fullFileNameWrt.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
> RtlCopyUnicodeString(&fullFileNameWrt,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&fullFileNameWrt, fileName);
>
> tempA.MaximumLength = fileName->MaximumLength +
> devExt->DeviceName.MaximumLength + 2;
> tempA.Buffer = ExAllocatePoolWithTag(NonPagedPool,
> tempA.MaximumLength,‘2leD’);
>
> if(NULL == tempA.Buffer) {
> DbgPrint(“\xxxxx@LACK OF RESOURCES…”);
> if(fullFileNameWrt.Buffer) {
> ExFreePoolWithTag(fullFileNameWrt.Buffer,‘pmoC’);
> }
> status = STATUS_INSUFFICIENT_RESOURCES;
> Irp->IoStatus.Status = status;
> Irp->IoStatus.Information = 0;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return status;
> }
>
> RtlCopyUnicodeString(&tempA,&devExt->DeviceName);
> RtlAppendUnicodeStringToString(&tempA, fileName);
>
> tempA.Buffer[tempA.Length] = L’\0’;
> tempA.Length = wcslen(tempA.Buffer) * sizeof(WCHAR);
> _wcsupr(tempA.Buffer);
>
>
> DbgPrint(“\xxxxx@JAI fullFileNameWrt:%wZ!”,&fullFileNameWrt);
> DbgPrint(“\xxxxx@JAI tempA:%wZ!”,&tempA);
> ////////////////////////
>
> But at most of the times while filtering , I am not getting the complete
> filepath in fullFileNameWrt although I am gettings fullfilepath in
>
> tempA unicode string
>
> JAI fullFileNameWrt: c:\Docum
> JAI tempA: C:\DOCUMENTS AND SETTINGS\NEW11\APPLICATION
> DATA\MACROMEDIA\FLASHPLAYER<br>>
> MACROMEDIA.COM\FLASHPLAYER\SYS\SETTIGS.SYX!
>
> ////////
> To know more I have added ! mark to check the end of filepath in my
> Dbgprints. But There is no ! mark found in fullFileNameWrt. (as shown in the
> above output)
>
>
> Can some body please tell what the problem exactly is ?? Is this happening
> because the file name is tooo big ??? Please help.
>
> Regards,
> Rohit
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@inquesttechnologies.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@inquesttechnologies.com
To unsubscribe send a blank email to xxxxx@lists.osr.com