Search code examples
cvisual-c++driverkernelwdk

Any Equivalent of strstr in Windows Kernel Mode?


I am writing a windows kernel mode driver in which I will have to manipulate lots of strings. Everywhere it has been advised to use "Safe String" functions instead of normal C functions. However, many of the string functions haven't been implemented e.g. strchr, strstr.

My question is whether there are any functions which I can use to search for strings within strings in kernel mode?


Solution

  • You can use regular C runtime functions like strstr() in a driver. Avoid focusing on finding a safe version of that function, none exists. There's no scenario where strchr() or strstr() can corrupt memory unintentionally. They only read, they don't write. They can certainly cause a blue screen if the input strings are not properly zero-terminated, producing an access violation. But that was a bug elsewhere.