[Mapguide_dev] svn commit: r1035 - Fixed a typo in FastCGI library for regular CGI mode

Walt Welton-Lair walt.welton-lair at autodesk.com
Sat Jan 6 20:27:06 EST 2007


r1035 | waltweltonlair | 2007-01-07 03:18:36 +0100 (Sun, 07 Jan 2007) |
33 lines

Fixed a typo in FastCGI library for regular CGI mode.

The MapAgent would fail when I tried to do a simple enumerate resource
request: I
would repeatedly get prompted for credentials.  So I debugged the agent
a little
and all the calls to getenv() were returning NULL.  Stepping a little
deeper, I
saw this code in fcgi_stdio.c:

    if(!acceptCalled) { 
        /* 
         * First call to FCGI_Accept.  Is application running 
         * as FastCGI or as CGI? 
         */ 
        isCGI = FCGX_IsCGI(); 
        acceptCalled = TRUE; 
        atexit(&FCGI_Finish); 
        origenv = environ; 
        while (NULL != *origenv) { ++origenvsize; ++origenv; } 
        origenv = environ; 
        environ = NULL; 
    } 

The last 4 lines of this if-block were recently added with submission
MG428. 

The problem is that environ is getting set to NULL.  This is an extern
variable
that is later used by getenv.  In the CGI case (isCGI=true) the environ
variable
is not getting reconstructed later on (see further down in the method).
So for
the CGI case getenv will fail.

The right thing to do is to only set environ to NULL if isCGI is false.
In that
case it will be reconstructed from the original environment, and so
getenv will
succeed.  In FCGI_Finish we free the environ variable if it's not NULL,
but only
for the non-CGI case.  So we're ok there too.

===================================================================
--- fcgi_stdio.c        (revision 1034)
+++ fcgi_stdio.c        (working copy)
@@ -122,10 +122,13 @@
         isCGI = FCGX_IsCGI();
         acceptCalled = TRUE;
         atexit(&FCGI_Finish);
-        origenv = environ;
-        while (NULL != *origenv) { ++origenvsize; ++origenv; }
-        origenv = environ;
-        environ = NULL;
+        if (!isCGI)
+        {
+            origenv = environ;
+            while (NULL != *origenv) { ++origenvsize; ++origenv; }
+            origenv = environ;
+            environ = NULL;
+        }

     } else if(isCGI) {
         /*

 W       E         @__   __o
   A   T   R   @___    _ \<,_
     L           @_   (*)/ (*)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide_dev/attachments/20070106/98a68a30/attachment.html


More information about the Mapguide_dev mailing list