Your else
branch contains only exec
command. perror
and exit
are non-conditional and will be executed in any case. Aside from that, string check is working as it should (unless you have custom (and incorrect) strstr
implementation).
Correct version is
else {
exec(argv[1],&argv[1],NULL);
perror("exec");
exit(1);
}