#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, char **argv) {
char *command;
if (argc != 2) {
fprintf (stderr, "Wrong number of arguments\n");
return 1;
}
if ((command = malloc (strlen (argv[1]) + 6)) == NULL) {
fprintf (stderr, "Could not allocate memory\n");
return 1;
}
strcpy (command, "echo ");
strcat(command,argv[1]);
system(command);
free (command);
return 0;
}
如何修补此代码,以便不会向用户提供任何特权 事情是通过运行这个我可以作为 root 用户访问如何编辑它以便这不会发生
最佳答案
调用seteuid(2)
在调用 system(3)
之前放弃 root 权限。
关于c - 你说它仍然会在后台运行一些东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5422363/