Re: argv[0] in execvp()

From: Gordon Burditt (gordonb.4a1p6_at_burditt.org)
Date: 11/26/05


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



Relevant Pages

  • Re: OO Design
    ... specify what data you want to keep about an attribute (metadata). ... there is not something like 'Config Time', ... The easiest way is to put all objects into an array, ... put the array in an attribute of the class descriptor, ...
    (comp.lang.php)
  • Re: [PHP] there has to be a better way...
    ... You may want to look into PEAR's config package. ... > - explode string into an array at the EOL marker ... > echo print_r; ... then it is redefined empty. ...
    (php.general)
  • Re: argv[0] in execvp()
    ... > Is the argument list for the new process image. ... > array of pointers to character strings, ... but the argv[] parameter is used by the linker to pass information ...
    (comp.unix.programmer)
  • Re: What declarations of main exist in the c standard?
    ... The presence of the third argument with environment variable ... executable file called the new process image file. ... where argc is the argument count and argv is an array of character ... terminated by a null pointer. ...
    (comp.lang.c)
  • Re: LSI Trouble (resend)
    ... When i tried to enter configuration console i have found out that all disks in my array are in READY state, that means they are not a part of any drive. ... After rebooting, server stopped to claim that configuration mismutch, but shows 0 Logical drives configured: ... In order to clear the NVRAM choose new config and then don't create any arrays. ...
    (freebsd-stable)