All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Bambach <eric@cisu.net>
To: linux-c-programming@vger.kernel.org
Subject: Re: array size 1 ? 	All headers
Date: Tue, 20 Jul 2004 22:18:52 -0500	[thread overview]
Message-ID: <200407202218.52955.eric@cisu.net> (raw)
In-Reply-To: <20040720235713.4cb83b20.lcapitulino@terra.com.br>

On Tuesday 20 July 2004 09:57 pm, you wrote:

Sorry Luiz, meant to send this to the list. Doh.....

>  compiles and works here! but to be honest, I don't why. I can prove it is
> an odd case, becase this also works (here):
>
>  char tst[1];
>  tst[0]='g';
>  tst[1]='r';
>  tst[2]='z';
>
>  printf("%c %c %c\n", tst[0], tst[1], tst[2]);
>
> PS: GCC compiled.


I think small overflows like this will work because arrays are allocated in 
multiples of the word size for the artitecture. So char 
ar[1];
gets 4 bytes as does char ar[2], char ar[3] and char ar[4].
char ar[5] will get 8 bytes. So  with ar[1] and ar[5] you can stuff up to 3 
more charaters until you overwrite critical parts of the stack. Its not an 
error per se, because the space is given to the array, but its a horrible 
thing to do in practice.

Someone correct me if I wrong, im typing this for the sake of teaching and 
learning myself.
-- 
-EB

  parent reply	other threads:[~2004-07-21  3:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-21  2:27 array size 1 ? All headers Gre Taguran
2004-07-21  2:57 ` Luiz Fernando N. Capitulino
2004-07-21  3:17   ` joy
2004-07-21 12:10     ` Luiz Fernando N. Capitulino
2004-07-21  3:18   ` Eric Bambach [this message]
2004-07-21  3:19   ` canbaby
2004-07-21  3:38   ` Glynn Clements
     [not found]   ` <200407202217.43875.eric@cisu.net>
2004-07-21 12:07     ` Luiz Fernando N. Capitulino

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=200407202218.52955.eric@cisu.net \
    --to=eric@cisu.net \
    --cc=linux-c-programming@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.