Question

I am trying to tell if the argument they give me is a Shared Library or a command I order to load the library or the exec with that especific command.

Right now what I am trying to do is:

if(strstr(argv[1],".so")!=NULL){
  //Load library etc...
}
else
  exec(argv[1],&argv[1],NULL);
  perror("exec");
  exit(1);

But it seems something its wrong because if the argument is "./lib.so" it tries exec(./lib.so).

Thank you in advance.

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top