Skip to contentSkip to conversation

Changing argv[0] under Linux.

DISCUSSION Peter Chubb 1 participant 1 message Jan 14, 2003 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Richard" == Richard B Johnson <[email protected]> writes:

Quoted 10 lines · DervishD
Quoted 10 lines

Hi Richard :)

Quoted 3 lines
Quoted 3 lines

Any header where I can see the length for argv[0] or is this SOME kind of unoficial standard? Just doing strcpy seems dangerous to me (you can read 'paranoid'...).

They need to have space for _POSIX_PATH_MAX (512 bytes), to claim POSIX compatibility so any POSIX system will have at least 512 bytes available because the pathname of the executable normally goes there.

No, because argv[0] is followed immediately by a NUL then argv[1], then argv[2], etc. They're not fixed length strings -- the kernel allocates just enough for the actual arguments, rounded up to PAGESIZE.

So if you copy more than strlen(argv[0]), you'll start overwriting argv[1].

--
Dr Peter Chubb [email protected]
You are lost in a maze of BitKeeper repositories, all almost the same.