c - 你说它仍然会在后台运行一些东西

标签 c linux

#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/

相关文章:

python - 使用不正确的 python 版本从 .deb 文件安装程序

linux - netcat 能否以直通方式工作

c - 为什么在许多驱动程序上,函数的返回值是用变量处理的?

c - C 中的 Getter 和 Setter

c - 科学计算::OpenMP 或 Pthreads

c - unsigned long 到 char 数组

c - posix_memalign 的系统调用中断

linux - 当前目录中文件根目录有 2 个下划线的文件

c - Initializer is not a constant 错误

c - 如何调整窗口大小以加载图像?