popen buffers output while system does not. is that the only difference?
I understand that popen and system both run the command through the shell. However, is popen() as evil as system()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look, the whole thing about “system being evil” is, at heart, people who don’t think about the security consequences of their particular use case. The only reason system is “more evil” than doing your own fork/dup/exec is that used badly, it’s possible for someone to introduce a malicious command line. So, for example
is certainly dumb, because someone could put, eg,
rm -rf /in as the argument. And, of course, something similarly dumb could be done with popen.But then consider something that does fork and exec using a user string for the command: the exact same vulnerability and stupidity exists.
The evil — which is to say, the error — lies in using a random input string as a command without some filtering, not in the system call.