Running the following C program with valgrind --leak-check=yes results in valgrind giving an output indicating that "Syscall param execve(argv) points to uninitialised byte(s)"
The following code is:
execv(commandCopy, cmd->argv);
fprintf(stderr, "%s: Command not found.\n", commandCopy);
free(cmd->argv);
free_cmd(cmd);
_exit(0);
According to valgrind, the problem occurs on the line:
==582489== Syscall param execve(argv) points to uninitialised byte(s)
==582489== at 0x49630FB: execve (syscall-template.S:120)
==582489== by 0x109FE5: parse_cmd (mysh.c:318)
==582489== by 0x109C53: parse_cmd (mysh.c:228)
==582489== by 0x10A25E: main (mysh.c:388)
What mistake have I made that causes valgrind to give this output?
Let's go through this slowly.
System calls (or syscalls) are the way that user code makes function calls into the kernel. Common system calls are open
, read
, write
, futex
. There are around 400 system calls.
A parameter of the syscall.
System call that replaces the current executable with another one.
The argument vector, which is the arguments that will be passed to the new executable.
The man page says
argv is an array of argument strings passed to the new program. By convention, the first of these strings should contain the filename associated with the file being executed. envp is an array of strings, conventionally of the form key=value, which are passed as environment to the new program. Both argv and envp must be terminated by a NULL pointer.
(I added the bold).
Some memory hasn't been assigned a value.
Either your argv
is NULL
, or more likely, you forgot to NULL
terminate the array of pointers to char*
that makes up argv
.