Re: kernel mode equivalent of strrchr

Tech-Archive recommends: Fix windows errors by optimizing your registry



What is complete? How much text processing is done in the kernel? How much
should be done? Since MS owns the OS, I guess they get to decide what are
the limits. I guess parsing a pathname in kernel mode might find that
routine useful, but you can just do it by scanning for a character saving
the position of each search loop. When you can't find it, then you have
saved the location of the last one. I noticed that there appears to be no
string search routines documented in the DDK. Maybe MS just wants keep the
string routines out of the kernel. They are not written, as we know from
experience, to be safe for kernel mode where any overrun or underrun can
cause the pretty BSOD.

"Mark Roddy" <markr@xxxxxxxxxxxxxx> wrote in message
news:uTNLg%23kOFHA.244@xxxxxxxxxxxxxxxxxxxxxxx
David J. Craig wrote:
The code modification is far too easy. The code in the CRT has a loop
that seeks to the end of the string. Since the ANSI_STRING has the
length of the string, just change the routine to use that information and
it will be even faster. The amount of code for such a routine is so
small and simple to understand that modifications to make it work in
drivers is trivial. Of course, it helps if you understand what makes
string functions safe so you don't create your own unsafe routine. Not
that hard. Run it under windbg and try different strings looking for any
place something can go wrong.


Well and good, however the kernel safe string library is revealed again to
be incomplete as it is missing basic string functions. Developers really
ought not to be wasting their time re-inventing the wheel.

"Doron Holan [MS]" <doronh@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:ObV%23KqaOFHA.2132@xxxxxxxxxxxxxxxxxxxxxxx

also note that the buffer in ANSI_STRING is *not* NULL terminated, it's
length is given in the structure. as such, you cannot use CRT functions
reliably.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no
rights.


"David J. Craig" <SeniorDriversWriter@xxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:%23Esa7aaOFHA.1176@xxxxxxxxxxxxxxxxxxxxxxx

Very bad idea. Try it at raised IRQL with driver verifier running.
This will be a good thing ;) Why not just use the source code that
ships with VC7 and adapt it to be safe using the techniques from
ntstrsafe.h? This is so easy, why even ask? School project?

"Bajamani" <bajamani@xxxxxxxxxxx> wrote in message
news:1112679603.328266.273920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

thank you.
i could not get safe equivalent of strchr. so converted the
UNICODE_STRING to ANSI_STRING and used strchr.
any other way anybody can think of ?

...Mani








--

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


.



Relevant Pages

  • Re: kernel mode equivalent of strrchr
    ... How much text processing is done in the kernel? ... routine useful, but you can just do it by scanning for a character saving ... string search routines documented in the DDK. ... >> string functions safe so you don't create your own unsafe routine. ...
    (microsoft.public.development.device.drivers)
  • Re: kernel mode equivalent of strrchr
    ... I guess parsing a pathname in kernel mode might find that routine useful, but you can just do it by scanning for a character saving the position of each search loop. ... I noticed that there appears to be no string search routines documented in the DDK. ... The situation after the advent of the safe string library is that there is now documented c runtime string support via the safe string libraries, ...
    (microsoft.public.development.device.drivers)
  • Re: kernel mode equivalent of strrchr
    ... Since the ANSI_STRING has the length of the string, just change the routine to use that information and it will be even faster. ... The amount of code for such a routine is so small and simple to understand that modifications to make it work in drivers is trivial. ... it helps if you understand what makes string functions safe so you don't create your own unsafe routine. ...
    (microsoft.public.development.device.drivers)
  • Re: kernel mode equivalent of strrchr
    ... Since the ANSI_STRING has the length of the string, just change the routine to use that information and it will be even faster. ... The amount of code for such a routine is so small and simple to understand that modifications to make it work in drivers is trivial. ... however the kernel safe string library is revealed again to be incomplete as it is missing basic string functions. ...
    (microsoft.public.development.device.drivers)
  • [PATCH] Ban module license tag string termination trick
    ... Proposed patch to prohibit loading modules that use early C string ... When this is interpreted back again in the kernel module loader, ... having wrongfully access to GPL symbols. ...
    (Linux-Kernel)