lkml.org 
[lkml]   [2003]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: Changing argv[0] under Linux.
>>>>> "Richard" == Richard B Johnson <root@chaos.analogic.com> writes:

Richard> On Tue, 14 Jan 2003, DervishD wrote:
>> Hi Richard :)
>>
>>>> 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 peterc@gelato.unsw.edu.au
You are lost in a maze of BitKeeper repositories, all almost the same.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.024 / U:1.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site