I want to execute an external program in lua. Usually this can be done with
os.execute("run '"..arg0.."' 'arg1' arg2")
The problem with this approach is if I want to pass user input as string to an external program, user input could be '; evil 'h4ck teh system' '
and the script from above would execute like this:
/bin/bash -c "run ''; evil 'h4ck teh system' '' 'arg1' arg2"
Another problem occurs when I have '$var'
as argument and the shell replaces this with its environment variable. In my particular case I have something like [[program 'set title "$My Title$"']]
– so nested strings – and program
parses "$My Title$"
(with escape sequences) differently than '$My Title$'
(as it is). Because I want to set the title as it, the best way is to have arguments like this: 'My Title'
. But now the command have to be:
os.execute([[run "set title '$My Title$'"]])
But now – as I said – $My
will be replaced with an empty string, because the environment does not know any variable named $My
and because, I never wanted it to be replaced.
So I am looking for the usual approach with
execv("run", {"set title '"..arg0.."'", arg1, arg2})