Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Przemek Klosowski <przemek@rrdjazz.nist.gov>
Subject: Re: Strange errors from strtok()
Date: Mon, 1 Dec 1997 16:09:27 -0500	[thread overview]
Message-ID: <199712012109.QAA15700@rrdjazz.nist.gov> (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

             reply	other threads:[~1997-12-01 21:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-01 21:09 Przemek Klosowski [this message]
     [not found] <199712012014.NAA14201@ellpspace.math.ualberta.ca>
1997-12-01 20:37 ` Strange errors from strtok() 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
read-only archive

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