New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix exec of shell script #677
Conversation
c9376d6
to
9e13ee0
Compare
9e13ee0
to
3227b24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the interpreter itself is another script, which has another interpreter (I have not seen such a scenario, nor do I know if it is valid)? In that case, recursion is possible. If it it is true, we can just put the string comparison inside elfType()
, since we are doing the magic number stuff anyway, and recursively call itself if the first line is an interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I think that the goal is that
elfType()
will work on an ELF binary, andgetInterpreterType()
will work on a script whose interpreter is an ELF binary. But a sciprt could have an interpreter that's a script. Why not turn this into a recursive function in whichgetInterpreterType()
is the recursive function, which first directly calls the base case (elfType()), and then if that fails, it calls the current body ofgetInterpeterType()
? If you're worried about infinite recursion for some weird buggy script, then you can limit to 10 tries or something. -
Note that this then allows you to clean up the excerpts of code in
src/dmtcp_launch.cpp
andsrc/execwrappers.cpp
. Instead of callilng both functions, you can simply call one recurseve function. -
Do you have a test case where exec of a shell script is failing under DMTCP, but succeeds under direct Linux? I tried to create an example, and failed. If you have a test case, could you add it to the test directory (autotest.py)?
Finally when I tried to produce a test case example, here are the pieces that I tried to build up.
The code corresponds, respectively, to the fiels: tmp.c
, tmp2.sh
, tmp.sh
. Hopefully, this is helpful to you:
int main() {
char *cmd[] = {"/tmp/tmp2.sh", "ls", NULL};
execve(cmd[0], cmd, NULL);
}
#!/tmp/tmp.sh
exec $1
#!/usr/bin/python
import os
import sys
os.system(sys.argv[1])
This fixes issue dmtcp#676.
3227b24
to
924c551
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This fixes issue #676.