我在使用 C 程序时遇到了一些神秘的事情,该程序在我的电脑上运行良好,但在我正在处理的服务器上编译它时却失败了。基本上 execve 的执行失败。原来的程序不是太大,所以我开始剪掉一些部分,以试图了解问题可能出在哪里。
这是程序的一个剪辑(它只是一个剪辑,所以当然它没有任何意义),好吧,在这里 execve 仍然失败:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>
int main (){
// Arguments
char *argv[100] = {"/home/input/input", [1 ... 99] = "A"};
//The real program would use some pipes later
int pipestdin[2];
int pipestderr[2];
pipe(pipestdin);
pipe(pipestderr);
// Call
char *env = "\xde\xad\xbe\xef=\xca\xfe\xba\xbe";
execve("/home/input/input",argv,&env); // Execute the program
printf("ERROR\n"); // printed only if execve fails
return 0;
}
但是当我拿出这部分时:
int pipestdin[2];
int pipestderr[2];
pipe(pipestdin);
pipe(pipestderr);
该程序再次开始工作。
以下是一些信息:
- 我电脑上的 gcc 版本:4.8.4
- 服务器上的 gcc 版本:4.6.3
- 上述程序的组装:http: //pastebin.com/nTagaErP
当我使用在我的电脑上编译的版本时,该程序在服务器上正常运行,这就是为什么我认为编译器有问题。