How can I escape variables sent to the 'system' command in C++?

前端 未结 5 1561
迷失自我
迷失自我 2021-01-18 18:19

This question talks about using the system command and passing variables. Here is an example it gives:

string cmd(\"curl -b cookie.txt -d test=\         


        
5条回答
  •  野的像风
    2021-01-18 18:56

    You can use environment variables to safely pass parameters to the comand executed by system(3)

    setenv ("mypar1", "'$(rm -rf /)", 1);
    setenv ("mypar2", "\"; rm -rf /", 1);
    system ("echo mypar1=\"$mypar1\" mypar2=\"$mypar2\");
    

    Neither of these evil codes will be executed, simply printed.

提交回复
热议问题