Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: Strange errors from strtok()
@ 1997-12-01 21:09 Przemek Klosowski
  0 siblings, 0 replies; 7+ messages in thread
From: Przemek Klosowski @ 1997-12-01 21:09 UTC (permalink / raw)


Your CGI program

   #include <stdio.h>
   #include <stdlib.h>
   char postline[80];
	...
   main()    {
	..
      while(gets(postline)!= NULL)       {
	..
      }
   }

   When I try to compile this program I get the following warnings:

   rsvp.c:20: warning: assignment makes pointer from integer without a cast
   rsvp.c:25: warning: assignment makes pointer from integer without a cast

   rsvp.c(.text+0x8c): the `gets' function is dangerous and should not be used.

I would forget the pointer/integer problem for now; the third warning basically
says that your CGI script is a wide-open security hole. The exploit: someone
sends you a line exceeding 80 characters; gets() obediently overflows your
measly 80 bytes and writes over other local variables, and then over the returning
stack frame. With some cunning, the attackers put a  fake stack frame pointing
to a chunk of their code in the same overlong CGI line (it requires some skill, but
is trivial otherwise). This results in them being able to run any code with the
permissions/privileges of the web server process. You should be using fgets(),
which will guarantee that your buffer will not overflow.

As to your strtok() problems, you should be including <string.h>.  I
think stdlib.h includes some but not all str... routines. Your code
may have worked on Intel, but just fortuitously. In general, gcc -Wall
is the right thing to do---it would have alerted you to lack of prototypes.
It is good practice to resolve all warnings given by -Wall.

-- 
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <199712012014.NAA14201@ellpspace.math.ualberta.ca>]
[parent not found: <19971201115108.03468@dot.cygnus.com>]
[parent not found: <01bcfe7f$60288060$323ccbd0@zeke.bainet.com>]

end of thread, other threads:[~1997-12-01 22:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-12-01 21:09 Strange errors from strtok() Przemek Klosowski
     [not found] <199712012014.NAA14201@ellpspace.math.ualberta.ca>
1997-12-01 20:37 ` Rob Zook
1997-12-01 22:15   ` Michal Jaegermann
     [not found] <19971201115108.03468@dot.cygnus.com>
1997-12-01 20:16 ` Rob Zook
     [not found] <01bcfe7f$60288060$323ccbd0@zeke.bainet.com>
1997-12-01 19:03 ` Rob Zook
1997-12-01 19:51   ` Richard Henderson
1997-12-01 20:14   ` Michal Jaegermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox