<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6618.4">
<TITLE>svn commit: r1035 - Fixed a typo in FastCGI library for regular CGI mode</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">r1035 | waltweltonlair | 2007-01-07 03:18:36 +0100 (Sun, 07 Jan 2007) | 33 lines</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Fixed a typo in FastCGI library for regular CGI mode.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">The MapAgent would fail when I tried to do a simple enumerate resource request: I</FONT>
<BR><FONT SIZE=2 FACE="Arial">would repeatedly get prompted for credentials. So I debugged the agent a little</FONT>
<BR><FONT SIZE=2 FACE="Arial">and all the calls to getenv() were returning NULL. Stepping a little deeper, I</FONT>
<BR><FONT SIZE=2 FACE="Arial">saw this code in fcgi_stdio.c:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> if(!acceptCalled) { </FONT>
<BR><FONT SIZE=2 FACE="Arial"> /* </FONT>
<BR><FONT SIZE=2 FACE="Arial"> * First call to FCGI_Accept. Is application running </FONT>
<BR><FONT SIZE=2 FACE="Arial"> * as FastCGI or as CGI? </FONT>
<BR><FONT SIZE=2 FACE="Arial"> */ </FONT>
<BR><FONT SIZE=2 FACE="Arial"> isCGI = FCGX_IsCGI(); </FONT>
<BR><FONT SIZE=2 FACE="Arial"> acceptCalled = TRUE; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> atexit(&FCGI_Finish); </FONT>
<BR><FONT SIZE=2 FACE="Arial"> origenv = environ; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> while (NULL != *origenv) { ++origenvsize; ++origenv; } </FONT>
<BR><FONT SIZE=2 FACE="Arial"> origenv = environ; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> environ = NULL; </FONT>
<BR><FONT SIZE=2 FACE="Arial"> } </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">The last 4 lines of this if-block were recently added with submission MG428. </FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">The problem is that environ is getting set to NULL. This is an extern variable</FONT>
<BR><FONT SIZE=2 FACE="Arial">that is later used by getenv. In the CGI case (isCGI=true) the environ variable</FONT>
<BR><FONT SIZE=2 FACE="Arial">is not getting reconstructed later on (see further down in the method). So for</FONT>
<BR><FONT SIZE=2 FACE="Arial">the CGI case getenv will fail.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">The right thing to do is to only set environ to NULL if isCGI is false. In that</FONT>
<BR><FONT SIZE=2 FACE="Arial">case it will be reconstructed from the original environment, and so getenv will</FONT>
<BR><FONT SIZE=2 FACE="Arial">succeed. In FCGI_Finish we free the environ variable if it's not NULL, but only</FONT>
<BR><FONT SIZE=2 FACE="Arial">for the non-CGI case. So we're ok there too.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">===================================================================</FONT>
<BR><FONT SIZE=2 FACE="Arial">--- fcgi_stdio.c (revision 1034)</FONT>
<BR><FONT SIZE=2 FACE="Arial">+++ fcgi_stdio.c (working copy)</FONT>
<BR><FONT SIZE=2 FACE="Arial">@@ -122,10 +122,13 @@</FONT>
<BR><FONT SIZE=2 FACE="Arial"> isCGI = FCGX_IsCGI();</FONT>
<BR><FONT SIZE=2 FACE="Arial"> acceptCalled = TRUE;</FONT>
<BR><FONT SIZE=2 FACE="Arial"> atexit(&FCGI_Finish);</FONT>
<BR><FONT SIZE=2 FACE="Arial">- origenv = environ;</FONT>
<BR><FONT SIZE=2 FACE="Arial">- while (NULL != *origenv) { ++origenvsize; ++origenv; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">- origenv = environ;</FONT>
<BR><FONT SIZE=2 FACE="Arial">- environ = NULL;</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ if (!isCGI)</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ {</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ origenv = environ;</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ while (NULL != *origenv) { ++origenvsize; ++origenv; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ origenv = environ;</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ environ = NULL;</FONT>
<BR><FONT SIZE=2 FACE="Arial">+ }</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> } else if(isCGI) {</FONT>
<BR><FONT SIZE=2 FACE="Arial"> /*</FONT>
</P>
<P><FONT SIZE=1 FACE="Courier New"> W E @__ __o</FONT>
<BR><FONT SIZE=1 FACE="Courier New"> A T R @___ _ \<,_</FONT>
<BR><FONT SIZE=1 FACE="Courier New"> L @_ (*)/ (*)</FONT>
</P>
</BODY>
</HTML>