If I ran the ssh command and logged into a server, would there be any reason to have code call system() since I can run it myself?
Edit: The code I have would be written in C
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.
system call will execute the program (with parameters) that you want. A system() call invokes a shell. So from inside of a C program, if you want to remove a file, you can invoke system with
"rm filename"as argument (this is just a use case – definitely not how you’d like to delete a file from a C program)You should use system() only when you know what you are doing. If a user input is any part of the argument to the system call, you should make sure you are sanitizing your input lest you are opening yourself to command injections.
An example of a command injections with system call is here
Alternatives to system are popen and obviously fork+exec.