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

> On Tue, 14 Jan 2003, DervishD wrote:
>
> > Hi all :))
> >
> > 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.

Last time must have been in an alternate reality.

You just overwrote all your arguments (argv[0] and others) and part of
the environment.

Try this for a change:

#include <stdio.h>
#include <string.h>
extern char ** _environ;
int main(int cnt, char *argv[]) {
char **eptr;
for ( eptr = _environ; *eptr; ++eptr )
printf("ENV before: %s\n", *eptr);
strcpy(argv[0], "How-long-do-you-want-this-string-to-be?--is-this-long-enough?");
for ( eptr = _environ; *eptr; ++eptr )
printf("ENV after: %s\n", *eptr);
pause();
return 0;
}

Phil.
-
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.112 / U:2.736 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site