fakedad fakedad - 1 year ago 105
C Question

Getting "Syscall param execve(argv) points to unaddressable byte(s)" in valgrind

Running the following C program with

valgrind --leak-check=yes
results in valgrind giving an output indicating that

Syscall param execve(argv) points to unaddressable byte(s)

The program is as follows:

int main() {
const int NUM_ARGS = 3;
char** run_arguments = malloc(sizeof(char*)*NUM_ARGS);
run_arguments[0] = "ls";
run_arguments[1] = "-l";
run_arguments[2] = "--color";
char* full_path = "/bin/ls";
int pid = fork();
if (pid == 0)
else {
int status;
return 0;

According to valgrind, the problem occurs on the line
, and the problem originates from the
done on the line
char** run_arguments = malloc(sizeof(char*)*NUM_ARGS);

What mistake have I made that causes valgrind to give this output?

Answer Source

The argument list must be terminated by a NULL pointer. Add one element to the run_arguments array, and have it be a NULL pointer.

Without the null pointer argument, the exec functions will go out of bounds in their search for the terminator, and will treat every non-null element as an argument that should be passed to the program. That leads to undefined behavior.

This is clearly noted in the exec manual page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download