Re: Changing argv[0] under Linux.

From: Philippe Troin (phil@fifi.org)
Date: Tue Jan 14 2003 - 15:25:54 EST


"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/



This archive was generated by hypermail 2b29 : Wed Jan 15 2003 - 22:00:51 EST