I would like to check if the environment variable that passed in the execve () function is actually passed , so I made this code (Main.c):
int main(){
char PATH[4];
strcpy(PATH, "bin");
char * newargv[] = {"./get","", (char*)0};
char * newenviron[] = {PATH};
execve("./get", newargv, newenviron);
perror("execve");
return 0;
}
(get.c):
int main()
{
const char* s = getenv("PATH");
printf("PATH :%s\n",s);
}
But, when I execute the binary file released by Main.c, I get this output:
PATH: (null)
whereas I want to see
PATH: bin
Do you have any explanation?
source
share