Couldn't find the answer by serching (maybe bad keywords), so I am creating a new question.
How do you handle parameter checking for dllexported methods with string parameters. The general rule is never trust user, but in reality? For example:
int foo(const char *bar)
{
if(!bar)
return FAIL;
???
}
Say the user of the library calls our function like:
foo(reinterpret_cast<char*>(0x00000008));
That should cause an AV on first:
strlen(bar);
Is there a way to guard against this? Correct approach to handle the error?
I know IsBadReadPtr is out of the question, because this function is in a class of dangerous and never to be used. But is there even a way I should and could handle the problem? I can't __declpec(dllexport) std::string, can I? Moreover, even if I would, the std::string has some sort of thread local storage or statics that cause access violations when used from different modules, as far as I know (caused by statics or different heaps?).
Is there a security risk in using these functions, stack overflow (R/E)IP overwrite, or is it just going to cause safe AV?