Subject: Re: gdb over ktrace
To: Manuel Bouyer <bouyer@antioche.lip6.fr>
From: None <cpg@aladdin.de>
List: tech-kern
Date: 04/17/2000 00:35:08
Hi,

On 04/15/2000 03:13:00 PM GMT Manuel Bouyer wrote:
>
>Linux has page 0 mapped R/W for userland. This is a real pain, because you
>can write programs that use invalid pointers and still work !!
>I'm teaching C programming to students under linux, and this is a problem:
>me: "if you use and uninitialised pointers it'll segfault"
>student: "but my program use a uninitialised pointer pointer to store a
>          string, it works !"

Hmm, which Linux version are you referring to?

When I try this program

------------ null.c
#include <stdio.h>

int main(void)
{
  char * myptr = NULL;
  char x;

  printf("before....\n"); fflush(stdout);
  x = *myptr;
  printf("after, x = %d\n",x);
  return(0);
}
------------

it crashes as expected:

gibbon:/tmp$ cc -o null null.c
gibbon:/tmp$ ./null
before....
Segmentation fault (core dumped)
gibbon:/tmp$ uname -a
Linux gibbon.cnet.aladdin.de 2.3.99-pre5 #3 SMP Sat Apr 15 00:58:25 CEST
2000 i686 unknown
gibbon:/tmp$

A check on a 2.0.29 and a 2.2.14 machine gives the same result (all i386),

Maybe the uninitialized pointers of your student's are automatic variables
on the
stack and reference memory  in a mapped region?

regards,
chris