1

I have this function:

int execve(const char* filename, char* const argv[], char* const envp[]); 

And I need set to NULL the envp parameter, so I need a pointer to NULL in the edx register before execute the function (better said, the syscall with int 0x80). The question is, can I do:

mov eax, 0
mov edx, eax  ; edx points to NULL, no to some address that contains NULL

or need I do:

push 0
mov edx, esp ; edx points to some address that contains NULL
Rob
  • 99
  • 1
  • 9

1 Answers1

1

It depends on the operation system. In Linux you can use directly a NULL pointer.

man execve:

On Linux, argv and envp can be specified as NULL. In both cases, this has the same effect as specifying the argument as a pointer to a list containing a single null pointer. Do not take advantage of this misfeature! It is nonstandard and nonportable: on most other UNIX systems doing this will result in an error (EFAULT).

rkhb
  • 14,159
  • 7
  • 32
  • 60