FastCGI / Apache problems

Bob Ramstad (
Thu, 29 Aug 1996 11:07:49 -0400 (EDT)

Date: Thu, 29 Aug 1996 11:07:49 -0400 (EDT)
From: Bob Ramstad <>
Message-Id: <>
In-Reply-To: Mark Brown's message of Mon, 26 Aug 1996 16:42:18 -0400 <>
Subject: FastCGI / Apache problems 

this is a trace from an FCGI application which is SIGSEGVing
occasionally... ideas?

(dbx) where
warning: core file read error: address not in data space
atoi() at 0xef777794
fd_extract_data() at 0x11acb8
grab_data(), line 254 in "tag.c"
main(argc = 1, argv = 0xefffffb4), line 135 in "tag.c"

the only call to atoi in fd_extract_data looks like this:

  char *method = getenv("REQUEST_METHOD");

  if (method && !strcmp (method, "POST")) {
      int length = atoi(getenv ("CONTENT_LENGTH"));
      query = malloc (length+1);
      if (length)
          fread (query, length, 1, stdin);
      query[length] = '\0';
  } else ...

note the workaround to the bug in fread (doesn't handle zero

i'm puzzled.  this is all occuring within the FCGI_Accept() i.e. all
the environment variables should be set appropriately, and if the
method is POST certainly CONTENT_LENGTH should be set --- this code
works fine for use in standard CGI with every server we've used (NCSA,
Apache, Netscape, Microsoft IIS, CERN, others).  it's also fairly
weird that it only occurs occasionally...

a quick look through mod_fastcgi.c and the libfcgi materials seems to
indicate that the environment which comes from the web server is being
faithfully reproduced in its entirety.  two options i see, then:

* i'm doing something "naughty" or wrong with my environment
variables.  i'm assuming it is OK to call putenv within the
FCGI_Accept loop as long as i only expect to access these variables
within this loop.  is this accurate?

for those who are curious, my concern here is to keep various
environment variables set for maintaining an Oracle connection.

* there's something wrong with Apache 1.1.1 and CONTENT_LENGTH

-- Bob