system() vs execve()
问题 Both system() and execve() can be used to execute another command inside a program. Why in set-UID programs, system() is dangerous, while execve() is safe ? 回答1: system will call the shell (sh) to execute the command sent as an argument. The problem with system because the shell behavior depends on the user who run the command. A small example: Creating a file test.c : #include <stdio.h> int main(void) { if (system ("ls") != 0) printf("Error!"); return 0; } Then: $ gcc test.c -o test $ sudo