Re: argv[0] in execvp()
From: Gordon Burditt (gordonb.4a1p6_at_burditt.org)
Date: 11/26/05
- Next message: Alex Fraser: "Re: while (wait(&status) != pid) and waitpid (pid, &status, 0)"
- Previous message: shakahshakah_at_gmail.com: "Re: Sed to match multiple patterns"
- In reply to: Alex Vinokur: "argv[0] in execvp()"
- Next in thread: Alex Vinokur: "Re: argv[0] in execvp()"
- Reply: Alex Vinokur: "Re: argv[0] in execvp()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Nov 2005 18:56:14 -0000
>argv
>Is the argument list for the new process image. This should contain an
>array of pointers to character strings, and the array should be
>terminated by a NULL pointer. The value in argv[0] should point to a
>file name that is associated with the process being started by the
>exec() function.
>-----------------------------------------------------
>
>
>Why should 'argv[0]' point to a file name?
Because some programs look at it and change their behavior based
on what they see there. For example, "cp" and "mv" may be
the same program and behave differently based on how they are called.
>Is not it enough the 'file' parameter to execute the program?
If you don't care whether it misbehaves when you run it, you
can pass anything. The program will still run.
Some (idiotic) programs attempt to find their other pieces (config
files, data, etc.) based on the directory of argv[0]. This approach
often involves requiring the installation directory for the executables
be writable by the user (so the app can put data files there, too),
which encourages viruses to tamper with or replace them.
Some programs attempt to find their own executable to read their
own symbol table, often to avoid coding a command lookup table,
so the user can type something like "qsort" and crash the program.
Reasons for passing strange stuff in argv[0]:
- To hide (poorly) what you are doing from people running "ps"
- To exploit security holes in setuid programs.
- To force programs using a stupid method of finding their config
files to use an alternate config file (often to break security).
Gordon L. Burditt
- Next message: Alex Fraser: "Re: while (wait(&status) != pid) and waitpid (pid, &status, 0)"
- Previous message: shakahshakah_at_gmail.com: "Re: Sed to match multiple patterns"
- In reply to: Alex Vinokur: "argv[0] in execvp()"
- Next in thread: Alex Vinokur: "Re: argv[0] in execvp()"
- Reply: Alex Vinokur: "Re: argv[0] in execvp()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|