UNICODE_STRING Copy problem...

Dear All,
In my filter driver application , i am getting problem in following piece of
code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i];
}
// and then i append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////

Where do you set renameFileName.Length after the copy ?

Why not use RtlCopyUnicodeString() and RtlAppendUnicodeToString() ?

Mark

At 07:10 AM 4/29/2004, Rohit Dhamija wrote:

Dear All,
In my filter driver application , i am getting problem in following piece of
code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i];
}
// and then i append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////


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

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

(1) Note that you don’t check for a failure from ExAllocatePoolWithTag;
(2) You never set renameFileName.Length
(3) You use a fixed-size buffer, even though you don’t know the size of
the input string.

(2) is why it doesn’t print. (1) will explain when at some point this
code blue screens (either when running low resource simulation or out in
the field on a machine with low memory.) (3) is going to cause it to
blue screen the moment we test with a 256 character file name.

Also, unless there’s some very strong reason, I’d suggest using paged
pool for strings.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Thursday, April 29, 2004 2:10 AM
To: ntfsd redirect
Subject: [ntfsd] UNICODE_STRING Copy problem…

Dear All,
In my filter driver application , i am getting problem in following
piece of code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i]; } // and then i
append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////


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

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

Thanks Mr. Mason

But how can we proceed when we donot know the length of the string in
advance ?? For example in this piece of code, is there anything i can do so
as not to fix the buffer size and make my code run properly in all cases ?
Regards,
Rohit

“Tony Mason” wrote in message news:xxxxx@ntfsd…
(1) Note that you don’t check for a failure from ExAllocatePoolWithTag;
(2) You never set renameFileName.Length
(3) You use a fixed-size buffer, even though you don’t know the size of
the input string.

(2) is why it doesn’t print. (1) will explain when at some point this
code blue screens (either when running low resource simulation or out in
the field on a machine with low memory.) (3) is going to cause it to
blue screen the moment we test with a 256 character file name.

Also, unless there’s some very strong reason, I’d suggest using paged
pool for strings.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Thursday, April 29, 2004 2:10 AM
To: ntfsd redirect
Subject: [ntfsd] UNICODE_STRING Copy problem…

Dear All,
In my filter driver application , i am getting problem in following
piece of code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i]; } // and then i
append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////


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

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

You do know the size of the string - the fileRename buffer from which
you are copying it has the size. If I were doing something like this I
might do it like:

UNICODE_STRING newString;
PUNICODE_STRING oldString = (PUNICODE_STRING) RandomPointerToCast;

newString.MaximumLength = oldString->Length + sizeof(WCHAR); // enough
for string + NULL terminator
newString.Length = 0;
newString.Buffer = ExAllocatePoolWithTag(PagedPool,
newString.MaximumLength, ’ gaT’);

If (NULL == newString.Buffer) {
/* add my error processing here */
}

RtlCopyUnicodeString(&newString, oldString);

In other words - COMPUTE the size of the string THEN allocate the size
you need.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Friday, April 30, 2004 3:29 AM
To: ntfsd redirect
Subject: Re:[ntfsd] UNICODE_STRING Copy problem…

Thanks Mr. Mason

But how can we proceed when we donot know the length of the string in
advance ?? For example in this piece of code, is there anything i can do
so as not to fix the buffer size and make my code run properly in all
cases ?
Regards,
Rohit

“Tony Mason” wrote in message news:xxxxx@ntfsd…
(1) Note that you don’t check for a failure from ExAllocatePoolWithTag;
(2) You never set renameFileName.Length
(3) You use a fixed-size buffer, even though you don’t know the size of
the input string.

(2) is why it doesn’t print. (1) will explain when at some point this
code blue screens (either when running low resource simulation or out in
the field on a machine with low memory.) (3) is going to cause it to
blue screen the moment we test with a 256 character file name.

Also, unless there’s some very strong reason, I’d suggest using paged
pool for strings.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Thursday, April 29, 2004 2:10 AM
To: ntfsd redirect
Subject: [ntfsd] UNICODE_STRING Copy problem…

Dear All,
In my filter driver application , i am getting problem in following
piece of code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i]; } // and then i
append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////


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

You are currently subscribed to ntfsd as: xxxxx@osr.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@osr.com To unsubscribe
send a blank email to xxxxx@lists.osr.com

Thanks!
That was very helpful in solving my problem .
Rohit
“Tony Mason” wrote in message news:xxxxx@ntfsd…
You do know the size of the string - the fileRename buffer from which
you are copying it has the size. If I were doing something like this I
might do it like:

UNICODE_STRING newString;
PUNICODE_STRING oldString = (PUNICODE_STRING) RandomPointerToCast;

newString.MaximumLength = oldString->Length + sizeof(WCHAR); // enough
for string + NULL terminator
newString.Length = 0;
newString.Buffer = ExAllocatePoolWithTag(PagedPool,
newString.MaximumLength, ’ gaT’);

If (NULL == newString.Buffer) {
/* add my error processing here */
}

RtlCopyUnicodeString(&newString, oldString);

In other words - COMPUTE the size of the string THEN allocate the size
you need.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Friday, April 30, 2004 3:29 AM
To: ntfsd redirect
Subject: Re:[ntfsd] UNICODE_STRING Copy problem…

Thanks Mr. Mason

But how can we proceed when we donot know the length of the string in
advance ?? For example in this piece of code, is there anything i can do
so as not to fix the buffer size and make my code run properly in all
cases ?
Regards,
Rohit

“Tony Mason” wrote in message news:xxxxx@ntfsd…
(1) Note that you don’t check for a failure from ExAllocatePoolWithTag;
(2) You never set renameFileName.Length
(3) You use a fixed-size buffer, even though you don’t know the size of
the input string.

(2) is why it doesn’t print. (1) will explain when at some point this
code blue screens (either when running low resource simulation or out in
the field on a machine with low memory.) (3) is going to cause it to
blue screen the moment we test with a 256 character file name.

Also, unless there’s some very strong reason, I’d suggest using paged
pool for strings.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rohit Dhamija
Sent: Thursday, April 29, 2004 2:10 AM
To: ntfsd redirect
Subject: [ntfsd] UNICODE_STRING Copy problem…

Dear All,
In my filter driver application , i am getting problem in following
piece of code , its written in irp_mj_set_information routine

//////////////////////////////////////////
PFILE_RENAME_INFORMATION fileRename;
UNICODE_STRING renameFileName;
renameFileName.MaximumLength = 200;
renameFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
renameFileName.MaximumLength,‘2leM’);

// I am getting Renamed file by:-
fileRename = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

*renameFileName.Buffer = L’\0’;

//After that I copy character by chacter into my unicode string

for(i=0; i < fileRename->FileNameLength/2; i++) {

renameFileName.Buffer[i] = fileRename->FileName[i]; } // and then i
append the string with null character

renameFileName.Buffer[i] = L’Q’;
renameFileName.Buffer[i] = L’\0’;

//When i print this string it shows nothing??? Can any body please tell
where is the flaw in the program

DbgPrint(“\nRENAME renameFileName %wZ!\n”, &renameFileName);

////////////////////////////////


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

You are currently subscribed to ntfsd as: xxxxx@osr.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@osr.com To unsubscribe
send a blank email to xxxxx@lists.osr.com