public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Miquel van Smoorenburg" <miquels@cistron.nl>
To: linux-kernel@vger.kernel.org
Subject: Re: Changing argv[0] under Linux.
Date: Tue, 14 Jan 2003 21:55:02 +0000 (UTC)	[thread overview]
Message-ID: <b020vm$bpm$1@ncc1701.cistron.net> (raw)
In-Reply-To: Pine.LNX.3.95.1030114140811.13496A-100000@chaos.analogic.com

In article <Pine.LNX.3.95.1030114140811.13496A-100000@chaos.analogic.com>,
Richard B. Johnson <root@chaos.analogic.com> 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[0]\0argv[1]\0\0
	*environ[];
	*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

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


  parent reply	other threads:[~2003-01-14 21:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-14 18:59 Changing argv[0] under Linux DervishD
2003-01-14 19:10 ` Richard B. Johnson
2003-01-14 19:14   ` DervishD
2003-01-14 19:43     ` Richard B. Johnson
2003-01-14 19:50       ` DervishD
2003-01-14 19:56         ` Richard B. Johnson
2003-01-14 20:23           ` Mark Mielke
2003-01-14 20:28             ` Richard B. Johnson
2003-01-14 21:21               ` Mark Mielke
2003-01-15 14:00                 ` Richard B. Johnson
2003-01-15 16:43                 ` Richard B. Johnson
2003-01-15 16:57                   ` DervishD
2003-01-14 22:00             ` DervishD
2003-01-21 14:16     ` Bill Davidsen
2003-01-21 15:33       ` DervishD
2003-01-14 20:25   ` Philippe Troin
2003-01-14 20:56     ` Richard B. Johnson
2003-01-14 22:04     ` DervishD
2003-01-14 23:04       ` Bob Miller
2003-01-14 23:11         ` Bob Miller
2003-01-15  4:46           ` Mark Mielke
2003-01-15  8:25             ` jw schultz
2003-01-15 11:41               ` DervishD
2003-01-15 13:16                 ` Jakob Oestergaard
2003-01-15 16:22                   ` DervishD
2003-01-15 16:47                     ` Jakob Oestergaard
2003-01-15 17:10                       ` DervishD
2003-01-15 17:36                         ` Changing argv[0] under Linux. This MUST work DervishD
2003-01-15 21:26                       ` Changing argv[0] under Linux Andreas Schwab
2003-01-15 21:36                         ` Jesse Pollard
2003-01-15 22:03                         ` DervishD
2003-01-16  9:19                           ` Dorin Lazar
2003-01-15 11:35         ` DervishD
2003-01-14 21:55   ` Miquel van Smoorenburg [this message]
2003-01-14 22:04     ` Valdis.Kletnieks
2003-01-15 11:28     ` DervishD
2003-01-27  7:47 ` Anuradha Ratnaweera
     [not found] <122203493@toto.iv>
2003-01-14 22:55 ` Peter Chubb
  -- strict thread matches above, loose matches on Subject: below --
2003-01-16 10:12 Jon Burgess
2003-01-16 10:32 ` DervishD
2003-01-16 11:31 Jon Burgess
2003-01-16 12:58 ` DervishD
     [not found] <20030116130013.GE1358@DervishD>
     [not found] ` <200301161315.h0GDFLM27487@isengard.accucard.com>
2003-01-17 10:08   ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='b020vm$bpm$1@ncc1701.cistron.net' \
    --to=miquels@cistron.nl \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox