argv[0] in execvp()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > argv[0] in execvp()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    argv[0] in execvp()  
Alex Vinokur


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-26-05 07:50 AM


QUOTES from http://www.mkssoftware.com/docs/man3/execl.3.asp

----------------------------------------------------
int execvp(const char *file, char *const argv[])

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?
Is not it  enough the 'file' parameter to execute the program?


Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn






[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-26-05 07:50 AM

"Alex Vinokur" <alexvn@users.sourceforge.net> writes:

> Why should 'argv[0]' point to a file name?

Convention.

> Is not it  enough the 'file' parameter to execute the program?

It is.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Lew Pitcher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-26-05 07:50 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alex Vinokur wrote:
> QUOTES from http://www.mkssoftware.com/docs/man3/execl.3.asp
>
> ----------------------------------------------------
> int execvp(const char *file, char *const argv[])
>
> 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?
> Is not it  enough the 'file' parameter to execute the program?

Nope. The file parameter is (in effect) used by the loader to load the binar
y,
but the argv[] parameter is (in effect) used by the linker to pass infor
mation
to the running binary.

While the manpage says to give the filename as argv[0], consider that so
me
times it is useful to pass other information as argv[0].  For instance,

argv[0] = "-";
argv[1] = NULL;
execvp("/bin/bash",argv);

Take a look at your login shell through ps. See the similarity?


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFDh/ ilagVFX4UWr64RAgSbAKCE4obSv0vt2bRJo4dsUE
sv7c7a/QCfTvTS
c7rNoxzKbY38b978uWGQQXw=
=NG3B
-----END PGP SIGNATURE-----





[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-26-05 07:50 AM

Lew Pitcher <lpitcher@sympatico.ca> writes:
 
>
> Nope. The file parameter is (in effect) used by the loader to load the bin
ary,
> but the argv[] parameter is (in effect) used by the linker to pass inf
ormation
> to the running binary.

Huh? Which linker are you talking about?

After the program is running, linker is not involved *at all*.
The runtime loader is involved, but it doesn't care about agrv[0]
on any UNIX I know.

> While the manpage says to give the filename as argv[0], consider that 
some
> times it is useful to pass other information as argv[0].  For instance
,
>
>   argv[0] = "-";
>   argv[1] = NULL;
>   execvp("/bin/bash",argv);
>
> Take a look at your login shell through ps. See the similarity?

So you've just confirmed that argv[0] does *not* need to be the
file name, contradicting your own earlier "Nope" statement.

Yes, exec()ed programs themselves could well care about values
of argv[0], argv[1], etc. They could also care about time of day,
or values of environment variables. But none of this is "required
to execute the program" (i.e. exec() it and get it to its entry
point).

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Gordon Burditt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-26-05 10:50 PM

>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





[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Alex Vinokur


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-27-05 10:53 PM


"Gordon Burditt" <gordonb.4a1p6@burditt.org> wrote in message news:11ohbueeg
kqnua8@corp.supernews.com...
[snip]
> Reasons for passing strange stuff in argv[0]:
>
> - To hide (poorly) what you are doing from people running "ps"

What is the relationship between "ps" and argv[0]?

> - To exploit security holes in setuid programs.

Similar question: what is the relationship between setuid programs and argv&
#91;0]?

[snip]

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn








[ Post a follow-up to this message ]



    Re: argv[0] in execvp()  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-27-05 10:53 PM

"Alex Vinokur" <alexvn@x-privat.org> writes:

> "Gordon Burditt" <gordonb.4a1p6@burditt.org> wrote in message news:11ohbue
egkqnua8@corp.supernews.com...
> [snip] 
>
> What is the relationship between "ps" and argv[0]?

ps usually displays whatever is in argv[0] as the process name.  If
you're doing something nasty, setting argv[0] to something
innocent-looking might delay detection.
 
>
> Similar question: what is the relationship between setuid programs
> and argv[0]?

Some programs do different things depending on the value of argv[0].
Passing a bizarre value might trigger a bug such as a buffer overflow.
This is obviously worse if it happens to a setuid program.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:32 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register