From C program, I want to call a shell script with the file name as a parameter. Users can control the file name. C is something like (initialization / error check omitted):
sprintf(buf, "/bin/sh script.sh \"%s\"", filename); system(buf);
The target device is actually an embedded system, so I donβt have to worry about malicious users. Obviously, this will be an attack vector in a web environment. However, if the system has a file name that, for example, contains backticks in its name, the command will fail because the shell will expand by name. Is there a way to prevent command substitution?
source share