[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: protection against buffer overflows



> #include <stdio.h>
> 
> void example()
> {
>   char a[10];
>   char b[10];
>   strcpy(a, "123456789");
>   printf ("a: %s\n", a);
>   b[20]='X';
>   b[21]='Y';
>   b[22]='Z';
>   printf("a: %s\n", a);
>   return;
> }
> main()
> {
> example();
> }
Ralf,
i ran this code
very interesting results, how? i would assume that the b buffer would
sit on the stack past the a buffer as it was declared afterward, and
also i'm confused of how assigning string lits to b beyond it's
allocation would affect a?  and wouldn't a still have a term null char?
obviously this is the problem everyone speaks of, is there a logical
explanation?
thanks,
steve



Reply to: