[lkml]   [2003]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Changing argv[0] under Linux.
In article <>,
Richard B. Johnson <> wrote:
>On Tue, 14 Jan 2003, DervishD wrote:
>> I'm not sure whether this issue belongs to the kernel or to the
>> libc, but I think that is more on the kernel side, that's why I ask
>> here.
>Last time I checked argv[0] was 512 bytes. Many daemons overwrite
>it with no problem.

No cigar. This stuff is all set up by the kernel on the stack;
in order you have

Top of stack at 0xbfffffff
environ[0]\0environ[1]\0\0 From high ..
*argv[]; .. to low.

The kernel only reserves space as needed. If you have an empty
environment, and you copy 512 bytes over argv[0], you'll end
up with a SEGV.

If you want to modify argv[0] etc, loop over argv[], count howmuch
space there is (strlen(argv[0] + 1 + strlen(argv[1] + 1 ... etc)
and make sure you do NOT write a string longer than that. Also
make sure that you end the string with a double \0

They all laughed when I said I wanted to build a joke-telling machine.
Well, I showed them! Nobody's laughing *now*! --

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

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