strcmp behavior
by igadoter from LinuxQuestions.org on (#5MD7B)
This
Code: int
main(int argc, char *argv[])
{
int res;
res = strcmp("foo", NULL);
exit(EXIT_SUCCESS);
}crashes with segfault while this
Code: int
main(int argc, char *argv[])
{
int res;
res = strcmp(NULL, NULL);
exit(EXIT_SUCCESS);
}does not crash. I have look at man strcmp but there is nothing about handling NULL arguments. I googled little: standard also does not provide such details. I consider this as kind of curiosity but also perhaps vulnerability which can be exploited - I mean passing both values NULL to strcmp.
Code: int
main(int argc, char *argv[])
{
int res;
res = strcmp("foo", NULL);
exit(EXIT_SUCCESS);
}crashes with segfault while this
Code: int
main(int argc, char *argv[])
{
int res;
res = strcmp(NULL, NULL);
exit(EXIT_SUCCESS);
}does not crash. I have look at man strcmp but there is nothing about handling NULL arguments. I googled little: standard also does not provide such details. I consider this as kind of curiosity but also perhaps vulnerability which can be exploited - I mean passing both values NULL to strcmp.