* Linux-2.4.22 memory overwriting
@ 2004-02-01 12:14 Julien Rebetez
2004-02-01 12:21 ` Hugo Mills
2004-02-01 12:33 ` Roberto Sanchez
0 siblings, 2 replies; 3+ messages in thread
From: Julien Rebetez @ 2004-02-01 12:14 UTC (permalink / raw)
To: linux-kernel
Hi !
I've writen the following program :
#include <stdio.h>
int main ()
{
int p[4];
p[0]=1;
p[1]=2;
p[2]=3;
p[3]=4;
p[4]=5;
printf ("%i, %i, %i, %i, %i\n", p[0], p[1], p[2], p[3],
p[4]);
return 0;
}
I compile it with :
gcc -o test test.c -Wall
and when i launch it, the output is :
julien:$> ./test
1, 2, 3, 4, 5
Should I not get a SIGSEV from the system ? Isn't it dangerous to allow
the user to put 5 elements in a 4 elements tab?
(tested on Linux 2.4.22 on a i686)
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Linux-2.4.22 memory overwriting
2004-02-01 12:14 Linux-2.4.22 memory overwriting Julien Rebetez
@ 2004-02-01 12:21 ` Hugo Mills
2004-02-01 12:33 ` Roberto Sanchez
1 sibling, 0 replies; 3+ messages in thread
From: Hugo Mills @ 2004-02-01 12:21 UTC (permalink / raw)
To: Julien Rebetez; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]
On Sun, Feb 01, 2004 at 01:14:37PM +0100, Julien Rebetez wrote:
> Hi !
> I've writen the following program :
[snip]
> Should I not get a SIGSEV from the system ? Isn't it dangerous to allow
> the user to put 5 elements in a 4 elements tab?
This is nothing to do the the kernel. It's to do with C.
Yes, it is dangerous to allow this behaviour. However, C doesn't
perform bounds checking on arrays -- this is left to the programmer to
ensure that an array is never accessed outside its bounds. The effects
of accessing (reading or writing) an array outside its bounds are
undefined. In this case, it's worked. In other situations, with
different arrays, it may not work.
Nothing to see here. Move along.
Hugo.
--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 1C335860 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- Well, you don't get to be a kernel hacker simply by looking ---
good in Speedos. -- Rusty Russell
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Linux-2.4.22 memory overwriting
2004-02-01 12:14 Linux-2.4.22 memory overwriting Julien Rebetez
2004-02-01 12:21 ` Hugo Mills
@ 2004-02-01 12:33 ` Roberto Sanchez
1 sibling, 0 replies; 3+ messages in thread
From: Roberto Sanchez @ 2004-02-01 12:33 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 877 bytes --]
Julien Rebetez wrote:
> Hi !
> I've writen the following program :
>
>
> #include <stdio.h>
>
> int main ()
> {
> int p[4];
> p[0]=1;
> p[1]=2;
> p[2]=3;
> p[3]=4;
> p[4]=5;
>
> printf ("%i, %i, %i, %i, %i\n", p[0], p[1], p[2], p[3],
> p[4]);
> return 0;
> }
>
> I compile it with :
>
> gcc -o test test.c -Wall
>
> and when i launch it, the output is :
>
> julien:$> ./test
> 1, 2, 3, 4, 5
>
> Should I not get a SIGSEV from the system ? Isn't it dangerous to allow
> the user to put 5 elements in a 4 elements tab?
>
> (tested on Linux 2.4.22 on a i686)
>
> Thanks
Remember that C was written by experts for use by experts. C makes
the unfortunate assumption that you know *exactly* what you are doing.
This flexibility is great for tho advanced system programmer, but
dangerous for the unwary.
-Roberto
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-02-01 12:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-01 12:14 Linux-2.4.22 memory overwriting Julien Rebetez
2004-02-01 12:21 ` Hugo Mills
2004-02-01 12:33 ` Roberto Sanchez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox