Re: [ntfsd] Copying the string In windows kernel programing

Note that the correct (although MS proprietary) syntax for the case you mention is the upsized array

WCHAR

The compiler enforces the restriction that these fields must be the last member in a structure and that sizeof() does not include them. They are simply a synonym for basic pointer arithmetic (WCHAR*)((UINT_PTR)p + sizeof(struct))

The short version is that you have an array of size one, so one element was coppied

Sent from Surface Pro

From: xxxxx@spamcop.net
Sent: ‎Monday‎, ‎June‎ ‎15‎, ‎2015 ‎3‎:‎29‎ ‎AM
To: Windows File Systems Devs Interest List

Vivek, “WCHAR[1]” defines a string precisely one character in length - that’s the significance of the 1. As soon as you try to write more than 1 character to it, you’re overflowing it (a “buffer overflow”, a common bug and security hole in general) - make the buffer the right size for the data it’s to hold, and check the length of string you’re trying to write to it.

You will often see “WCHAR[1]” inside Windows structure definitions where that string is at the end of a variable-size structure. That works because you effectively override the 1 when you allocate the size of the structure it’s in - but that isn’t what you’re doing here.

Your next problem is likely to be that sizeof(MessageCommand->Data) is not actually the size or length of the input string.


NTFSD is sponsored by OSR

OSR is hiring!! Info at http://www.osr.com/careers

For our schedule of debugging and file system seminars 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

https://msdn.microsoft.com/en-us/library/b6fae073.aspx

Sent from Surface Pro

From: Maxim S. Shatskih
Sent: ‎Monday‎, ‎June‎ ‎15‎, ‎2015 ‎7‎:‎35‎ ‎PM
To: Windows File Systems Devs Interest List

This is C standard syntax and not MS proprietary, but banned in C++

I always prefer using (PWSTR)( MyStruct + 1 ) instead of this.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

“Marion Bond” wrote in message news:xxxxx@ntfsd…

Note that the correct (although MS proprietary) syntax for the case you mention is the upsized array

WCHAR

The compiler enforces the restriction that these fields must be the last member in a structure and that sizeof() does not include them. They are simply a synonym for basic pointer arithmetic (WCHAR*)((UINT_PTR)p + sizeof(struct))

The short version is that you have an array of size one, so one element was coppied

Sent from Surface Pro

From: xxxxx@spamcop.net
Sent: ‎Monday‎, ‎June‎ ‎15‎, ‎2015 ‎3‎:‎29‎ ‎AM
To: Windows File Systems Devs Interest List

Vivek, “WCHAR[1]” defines a string precisely one character in length - that’s the significance of the 1. As soon as you try to write more than 1 character to it, you’re overflowing it (a “buffer overflow”, a common bug and security hole in general) - make the buffer the right size for the data it’s to hold, and check the length of string you’re trying to write to it.

You will often see “WCHAR[1]” inside Windows structure definitions where that string is at the end of a variable-size structure. That works because you effectively override the 1 when you allocate the size of the structure it’s in - but that isn’t what you’re doing here.

Your next problem is likely to be that sizeof(MessageCommand->Data) is not actually the size or length of the input string.


NTFSD is sponsored by OSR

OSR is hiring!! Info at http://www.osr.com/careers

For our schedule of debugging and file system seminars 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

OSR is hiring!! Info at http://www.osr.com/careers

For our schedule of debugging and file system seminars 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