Concatenate UNICODE_STRINGs?

I need to concatenate UNICODE_STRINGS and have been reading the documentation and am not sure that there is a support routine that will do what I am
looking for. What I would like is to do RtlUnicodeStringCat( Dest, Src ) where the routine would do a check for overflowing Dest, and if so, allocate
a new buffer, copy the old to the new, free the old, then append the src. Is there such a thing? I see RtlUnicodeStringCatEx, but it looks like it
just will put the overflow data somewhere else. Obviously I could roll my own, but I was hoping that these sorts of routines would already be
written.
Thanks, Michael

Oh you are going to have to write your own function to do that. It
isn’t difficult as you have the length of both strings and buffers in
the UNICODE_STRING structure itself.

Mark Roddy

On Mon, Jan 3, 2011 at 6:50 PM, Michael Wade wrote:
> I need to concatenate UNICODE_STRINGS and have been reading the documentation and am not sure that there is a support routine that will do what I am
> looking for. ?What I would like is to do RtlUnicodeStringCat( Dest, Src ) where the routine would do a check for overflowing Dest, and if so, allocate
> a new buffer, copy the old to the new, free the old, then append the src. ?Is there such a thing? ?I see RtlUnicodeStringCatEx, but it looks like it
> just will put the overflow data somewhere else. ?Obviously I could roll my own, but I was hoping that these sorts of routines would already be
> written.
> Thanks, Michael
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>

OK, thanks for the response. But what I don’t understand is why this sort of routine isn’t in place already from MS? Isn’t this an obvious routine?

On Mon, 3 Jan 2011 19:00:13 -0500, Mark Roddy wrote:

>Oh you are going to have to write your own function to do that. It
>isn’t difficult as you have the length of both strings and buffers in
>the UNICODE_STRING structure itself.
>
>Mark Roddy
>
>
>
>On Mon, Jan 3, 2011 at 6:50 PM, Michael Wade wrote:
>> I need to concatenate UNICODE_STRINGS and have been reading the documentation and am not sure that there is a support routine that will do what I am
>> looking for. What I would like is to do RtlUnicodeStringCat( Dest, Src ) where the routine would do a check for overflowing Dest, and if so, allocate
>> a new buffer, copy the old to the new, free the old, then append the src. Is there such a thing? I see RtlUnicodeStringCatEx, but it looks like it
>> just will put the overflow data somewhere else. Obviously I could roll my own, but I was hoping that these sorts of routines would already be
>> written.
>> Thanks, Michael
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other 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
>>

There are RtlAppendUnicodeStringToString and RtlAppendUnicodeToString functions for this purpose. However, they’ll only succeed if the destination string is sufficiently sized. (There is no standard for how you must allocate the string storage for a UNICODE_STRING, which could even point into constant strings, so there’s no way for these functions to know how to reallocate the string storage to expand it. If you provide a sufficiently large storage region, however, the above RTL APIs may be used.)

Be sure to account for the fact the maximum length of a UNICODE_STRING is 64k bytes when managing string append, especially if your strings come from untrusted sources such as user mode.

  • S

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Michael Wade
Sent: Monday, January 03, 2011 3:51 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Concatenate UNICODE_STRINGs?

I need to concatenate UNICODE_STRINGS and have been reading the documentation and am not sure that there is a support routine that will do what I am looking for. What I would like is to do RtlUnicodeStringCat( Dest, Src ) where the routine would do a check for overflowing Dest, and if so, allocate a new buffer, copy the old to the new, free the old, then append the src. Is there such a thing? I see RtlUnicodeStringCatEx, but it looks like it just will put the overflow data somewhere else. Obviously I could roll my own, but I was hoping that these sorts of routines would already be written.
Thanks, Michael


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other 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

Auto allocate is a real pain in the *ss to deal with as it imposes
policy that only works for some use cases - which pool and what tag
and who (auto-)deallocates and when? There are very few routines that
do this and I avoid this feature like the plague whenever possible.

Mark Roddy

On Mon, Jan 3, 2011 at 7:53 PM, Michael Wade wrote:
> OK, thanks for the response. ?But what I don’t understand is why this sort of routine isn’t in place already from MS? ?Isn’t this an obvious routine?
>
> On Mon, 3 Jan 2011 19:00:13 -0500, Mark Roddy wrote:
>
>>Oh you are going to have to write your own function to do that. It
>>isn’t difficult as you have the length of both strings and buffers in
>>the UNICODE_STRING structure itself.
>>
>>Mark Roddy
>>
>>
>>
>>On Mon, Jan 3, 2011 at 6:50 PM, Michael Wade wrote:
>>> I need to concatenate UNICODE_STRINGS and have been reading the documentation and am not sure that there is a support routine that will do what I am
>>> looking for. ?What I would like is to do RtlUnicodeStringCat( Dest, Src ) where the routine would do a check for overflowing Dest, and if so, allocate
>>> a new buffer, copy the old to the new, free the old, then append the src. ?Is there such a thing? ?I see RtlUnicodeStringCatEx, but it looks like it
>>> just will put the overflow data somewhere else. ?Obviously I could roll my own, but I was hoping that these sorts of routines would already be
>>> written.
>>> Thanks, Michael
>>>
>>> —
>>> NTDEV is sponsored by OSR
>>>
>>> For our schedule of WDF, WDM, debugging and other 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
>>>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other 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
>

>Be sure to account for the fact the maximum length of a UNICODE_STRING is 64k bytes when

managing string append, especially if your strings come from untrusted sources such as user mode.

It is always 64K since the length field is 16bit, user mode or not so.


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

“Maxim S. Shatskih” wrote in message news:xxxxx@ntdev…

It is always 64K since the length field is 16bit, user mode or not so.

But if the user app sends you multiple strings to concatenate the length of
all strings combined can be > 64K (I actually had to fix a driver that did
this one, total PITA).

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

Hope to see you at the next OSR kernel debugging class February 14th in
Columbia, MD!