I'm experiencing something mysterious with a C program which works fine on my pc but fails when I compile it on the server I'm working on. Basically the execution of execve fails. The original program is not too big so I started to cut some parts in order to try to understand where could be the problem.
Here a cut of the program (it's just a cut so of-course it doesn't make any sense), well, in here execve still fails:
#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;
}
but when I take out this part:
int pipestdin[2];
int pipestderr[2];
pipe(pipestdin);
pipe(pipestderr);
the program starts to work again.
Here is some information:
- gcc version on my pc: 4.8.4
- gcc version on the server: 4.6.3
- Assembly of the program above: http://pastebin.com/nTagaErP
The program works normally on the server when I use the version compiled on my pc, that's why I suppose there is a problem with the compiler.