strcmp?

How do I properly do a strcmp() for ‘L’ strings?

I found:

http://msdn.microsoft.com/en-us/library/aa489561.aspx

which is helpful for some things.

Thx
-PWM

RtlInitUnicodeString + RtlCompareUnicodeString

Zero-terminated strings are no so convinient in the world where all strings are UNICODE_STRING

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

----- Original Message -----
From: “Peter W. Morreale”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, December 01, 2009 3:34 AM
Subject: [ntdev] strcmp?

>
> How do I properly do a strcmp() for ‘L’ strings?
>
> I found:
>
> http://msdn.microsoft.com/en-us/library/aa489561.aspx
>
> which is helpful for some things.
>
>
> Thx
> -PWM
>
>
> —
> 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
>

Peter W. Morreale wrote:

How do I properly do a strcmp() for ‘L’ strings?

_wcscmp. In general, the wide version of “strxxx” is “_wcsxxx”, and the
adaptable version is “_tcsxxx”.

Although _wcscmp is available in a driver, you should probably consider
RtlCompareUnicodeStrings.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I don’t think they are _wcs; it is just wcs for the wide-string C library.

But, as observed, it is not clear why these subroutines would work in a
world in which most strings are not NUL-terminated.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Monday, November 30, 2009 7:52 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] strcmp?

Peter W. Morreale wrote:

How do I properly do a strcmp() for ‘L’ strings?

_wcscmp. In general, the wide version of “strxxx” is “_wcsxxx”, and the
adaptable version is “_tcsxxx”.

Although _wcscmp is available in a driver, you should probably consider
RtlCompareUnicodeStrings.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


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


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

How about RtlCompareString, RtlEqualString, and/or RtlCompareUnicodeString?

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter W. Morreale
Sent: Monday, November 30, 2009 6:34 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] strcmp?

How do I properly do a strcmp() for ‘L’ strings?

I found:

http://msdn.microsoft.com/en-us/library/aa489561.aspx

which is helpful for some things.

Thx
-PWM


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

__________ Information from ESET Smart Security, version of virus signature
database 4650 (20091130) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature
database 4650 (20091130) __________

The message was checked by ESET Smart Security.

http://www.eset.com

Joseph M. Newcomer wrote:

I don’t think they are _wcs; it is just wcs for the wide-string C library.

…which is exactly what you get with an L"xxx" string, as he mentioned.

But, as observed, it is not clear why these subroutines would work in a
world in which most strings are not NUL-terminated.

You are correct, I should have asked for a snippet first.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Actually to be safe,

RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years why
Microsoft has not depricated RtlInitUnicodeString since it does a strlen
(one of those nasty deprecated NULL terminated string functions).


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

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

Zero-terminated strings are no so convinient in the world where all
strings are UNICODE_STRING

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

----- Original Message -----
From: “Peter W. Morreale”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, December 01, 2009 3:34 AM
Subject: [ntdev] strcmp?

>
> How do I properly do a strcmp() for ‘L’ strings?
>
> I found:
>
> http://msdn.microsoft.com/en-us/library/aa489561.aspx
>
> which is helpful for some things.
>
>
> Thx
> -PWM
>
>
> —
> 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
>

Information from ESET NOD32 Antivirus, version of virus signature
database 4650 (20091130)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4650 (20091130)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Don Burn wrote:

Actually to be safe,

RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years why
Microsoft has not depricated RtlInitUnicodeString since it does a strlen
(one of those nasty deprecated NULL terminated string functions).

strlen may be out of fashion, but it’s not unsafe, like strcpy and the like.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On Mon, 2009-11-30 at 17:25 -0800, Tim Roberts wrote:

Don Burn wrote:
> Actually to be safe,
>
> RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
> UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years why
> Microsoft has not depricated RtlInitUnicodeString since it does a strlen
> (one of those nasty deprecated NULL terminated string functions).
>

strlen may be out of fashion, but it’s not unsafe, like strcpy and the like.

I would argue that it is unsafe, since a unicode string appears to be
terminated with a UNICODE_NULL.

Since the time and trouble was made to encapsulate, with a vast array of
routines, changing that character (array?) to something else would break
a lot of code I imagine. Hopefully that will not happen.

:slight_smile:

But thanks for the pointers…

-PWM

Peter W. Morreale wrote:

On Mon, 2009-11-30 at 17:25 -0800, Tim Roberts wrote:

> Don Burn wrote:
>
>> Actually to be safe,
>>
>> RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
>> UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years why
>> Microsoft has not depricated RtlInitUnicodeString since it does a strlen
>> (one of those nasty deprecated NULL terminated string functions).
>>
>>
> strlen may be out of fashion, but it’s not unsafe, like strcpy and the like.
>

I would argue that it is unsafe, since a unicode string appears to be
terminated with a UNICODE_NULL.

Well, Don said “strlen” but he meant “_wcslen”. Running strlen on most
Unicode strings returns 1.

There is an unfortunate terminology problem when talking about strings
in the kernel. When user-mode programmers say “Unicode string”, they
usually mean a zero-terminated array of wchar_t. When kernel-mode
programmers say “Unicode string”, they often mean a UNICODE_STRING,
which is a structure with a current length, a maximum length, and a
pointer to an array of wchar_t that usually does NOT have a zero terminator.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On Mon, 2009-11-30 at 17:58 -0800, Tim Roberts wrote:

Peter W. Morreale wrote:
> On Mon, 2009-11-30 at 17:25 -0800, Tim Roberts wrote:
>
>> Don Burn wrote:
>>
>>> Actually to be safe,
>>>
>>> RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
>>> UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years why
>>> Microsoft has not depricated RtlInitUnicodeString since it does a strlen
>>> (one of those nasty deprecated NULL terminated string functions).
>>>
>>>
>> strlen may be out of fashion, but it’s not unsafe, like strcpy and the like.
>>
>
> I would argue that it is unsafe, since a unicode string appears to be
> terminated with a UNICODE_NULL.
>

Well, Don said “strlen” but he meant “_wcslen”. Running strlen on most
Unicode strings returns 1.

There is an unfortunate terminology problem when talking about strings
in the kernel. When user-mode programmers say “Unicode string”, they
usually mean a zero-terminated array of wchar_t. When kernel-mode
programmers say “Unicode string”, they often mean a UNICODE_STRING,
which is a structure with a current length, a maximum length, and a
pointer to an array of wchar_t that usually does NOT have a zero terminator.

Rats. My small dig prematurely terminated.

:wink:

-PWM

I did mean _wcslen, but I disagree with the claim it is unsafe. The reason
there is the safe string versions of the length function is that bad things
happen when you pass in a non-NULL terminated string. I have debugged a
case where RtlInitUnicodeString had a variable parameter and in rare
instances the NULL was missing. The BSOD nicely indited
RtlInitUnicodeString, but finding the problem was a bear, in the end I wrote
the equivalent of the safe string length function (this was before the safe
string functions were out there).


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Peter W. Morreale wrote:
>> On Mon, 2009-11-30 at 17:25 -0800, Tim Roberts wrote:
>>
>>> Don Burn wrote:
>>>
>>>> Actually to be safe,
>>>>
>>>> RtlUnicodeStringCbCopyStringW or RtlStringCbLength to build the
>>>> UNICODE_STRING then RtlCompareUnicodeString. I’ve wondered for years
>>>> why
>>>> Microsoft has not depricated RtlInitUnicodeString since it does a
>>>> strlen
>>>> (one of those nasty deprecated NULL terminated string functions).
>>>>
>>>>
>>> strlen may be out of fashion, but it’s not unsafe, like strcpy and the
>>> like.
>>>
>>
>> I would argue that it is unsafe, since a unicode string appears to be
>> terminated with a UNICODE_NULL.
>>
>
> Well, Don said “strlen” but he meant “_wcslen”. Running strlen on most
> Unicode strings returns 1.
>
> There is an unfortunate terminology problem when talking about strings
> in the kernel. When user-mode programmers say “Unicode string”, they
> usually mean a zero-terminated array of wchar_t. When kernel-mode
> programmers say “Unicode string”, they often mean a UNICODE_STRING,
> which is a structure with a current length, a maximum length, and a
> pointer to an array of wchar_t that usually does NOT have a zero
> terminator.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4651 (20091201)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Information from ESET NOD32 Antivirus, version of virus signature database 4651 (20091201)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com