Skip to content
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

Merged
merged 1 commit into from Sep 8, 2020
Merged

Fix exec of shell script #677

merged 1 commit into from Sep 8, 2020

Conversation

rohgarg
Copy link
Contributor

@rohgarg rohgarg commented Feb 12, 2018

This fixes issue #676.

Copy link
Contributor

@jiajuncao jiajuncao left a 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.

src/util_exec.cpp Outdated Show resolved Hide resolved
src/util_exec.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@gc00 gc00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think that the goal is thatelfType() will work on an ELF binary, and getInterpreterType() 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 which getInterpreterType() is the recursive function, which first directly calls the base case (elfType()), and then if that fails, it calls the current body of getInterpeterType()? If you're worried about infinite recursion for some weird buggy script, then you can limit to 10 tries or something.

  2. Note that this then allows you to clean up the excerpts of code in src/dmtcp_launch.cpp and src/execwrappers.cpp. Instead of callilng both functions, you can simply call one recurseve function.

  3. 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])

@gc00 gc00 added 2.6.1 and removed 2.6.0 labels Jul 5, 2019
Copy link
Contributor

@gc00 gc00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rohgarg rohgarg merged commit 114f5d5 into dmtcp:master Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants