myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-271


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-271-g1c01f9f
Date: Wed, 23 Jun 2010 15:02:27 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  1c01f9f9491cb6f61df071666a784de603b0acc6 (commit)
       via  0fafdf621cd32cd452074721d8dc3860c4aa7007 (commit)
       via  2eab3e3fed1ddd84bb877c7eb737e4702d60ee06 (commit)
       via  d05067a9f29fa83925d215eaf7d9b44957dbeaa3 (commit)
      from  fa279d5ec14c26dabb0b80e79bbb03d337c2eeda (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 1c01f9f9491cb6f61df071666a784de603b0acc6
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Jun 23 17:00:39 2010 +0200

    Read correctly the request payload when the Content-Length is not specified.

diff --git a/myserver/src/protocol/http/env/env.cpp 
b/myserver/src/protocol/http/env/env.cpp
index 3a413d0..f7ad3cf 100644
--- a/myserver/src/protocol/http/env/env.cpp
+++ b/myserver/src/protocol/http/env/env.cpp
@@ -42,9 +42,9 @@ using namespace std;
   \param cgiEnv The zero terminated list of environment string.
   \param processEnv Specify if add current process environment
   variables too.
- */
+*/
 void Env::buildEnvironmentString (HttpThreadContext* td, char *cgiEnv,
-                                 int processEnv)
+                                  int processEnv)
 {
   MemBuf memCgi;
   MemBuf portBuffer;
@@ -81,8 +81,8 @@ void Env::buildEnvironmentString (HttpThreadContext* td, char 
*cgiEnv,
 
   memCgi << end_str << "SERVER_ADMIN=";
   memCgi << td->securityToken.getData ("server.admin",
-                                             MYSERVER_VHOST_CONF |
-                                             MYSERVER_SERVER_CONF, "");
+                                       MYSERVER_VHOST_CONF |
+                                       MYSERVER_SERVER_CONF, "");
 
   memCgi << end_str << "REQUEST_METHOD=";
   memCgi << td->request.cmd.c_str ();
@@ -97,41 +97,39 @@ void Env::buildEnvironmentString (HttpThreadContext* td, 
char *cgiEnv,
   memCgi << end_str << "GATEWAY_INTERFACE=CGI/1.1";
 
   if (td->request.contentLength.length ())
-  {
-    memCgi << end_str << "CONTENT_LENGTH=";
-    memCgi << td->request.contentLength.c_str ();
-  }
+    {
+      memCgi << end_str << "CONTENT_LENGTH=";
+      memCgi << td->request.contentLength.c_str ();
+    }
   else
-  {
-    u_long fs = 0;
-    ostringstream stream;
-
-    if (td->inputData.getHandle () >= 0)
-      fs = td->inputData.getFileSize ();
-
-    stream << fs;
+    {
+      u_long fs = 0;
+      ostringstream stream;
 
-    memCgi << end_str << "CONTENT_LENGTH=" << stream.str ().c_str ();
-  }
+      if (td->inputData.getHandle () >= 0)
+        fs = td->inputData.getFileSize ();
 
+      stream << fs;
+      memCgi << end_str << "CONTENT_LENGTH=" << stream.str ().c_str ();
+    }
 
   if (td->request.rangeByteBegin || td->request.rangeByteEnd)
-  {
-    ostringstream rangeBuffer;
-    memCgi << end_str << "HTTP_RANGE=" << td->request.rangeType << "=" ;
-    if (td->request.rangeByteBegin)
     {
-      rangeBuffer << static_cast<int>(td->request.rangeByteBegin);
-      memCgi << rangeBuffer.str ();
-    }
-    memCgi << "-";
-    if (td->request.rangeByteEnd)
-    {
-      rangeBuffer << td->request.rangeByteEnd;
-      memCgi << rangeBuffer.str ();
-    }
+      ostringstream rangeBuffer;
+      memCgi << end_str << "HTTP_RANGE=" << td->request.rangeType << "=" ;
+      if (td->request.rangeByteBegin)
+        {
+          rangeBuffer << static_cast<int>(td->request.rangeByteBegin);
+          memCgi << rangeBuffer.str ();
+        }
+      memCgi << "-";
+      if (td->request.rangeByteEnd)
+        {
+          rangeBuffer << td->request.rangeByteEnd;
+          memCgi << rangeBuffer.str ();
+        }
 
-  }
+    }
 
   memCgi << end_str << "CGI_ROOT=";
   memCgi << td->cgiRoot;
@@ -152,18 +150,18 @@ void Env::buildEnvironmentString (HttpThreadContext* td, 
char *cgiEnv,
 
 
   if (td->pathInfo.length ())
-  {
-    memCgi << end_str << "PATH_INFO=";
-    memCgi << td->pathInfo;
+    {
+      memCgi << end_str << "PATH_INFO=";
+      memCgi << td->pathInfo;
 
-    memCgi << end_str << "PATH_TRANSLATED=";
-    memCgi << td->pathTranslated;
-  }
+      memCgi << end_str << "PATH_TRANSLATED=";
+      memCgi << td->pathTranslated;
+    }
   else
-  {
-    memCgi << end_str << "PATH_TRANSLATED=";
-    memCgi << td->filenamePath;
-  }
+    {
+      memCgi << end_str << "PATH_TRANSLATED=";
+      memCgi << td->filenamePath;
+    }
 
   memCgi << end_str << "SCRIPT_FILENAME=";
   memCgi << td->filenamePath;
@@ -171,7 +169,7 @@ void Env::buildEnvironmentString (HttpThreadContext* td, 
char *cgiEnv,
   /*
     For the DOCUMENT_URI and SCRIPT_NAME copy the
     requested uri without the pathInfo.
-   */
+  */
   memCgi << end_str << "SCRIPT_NAME=";
   memCgi << td->request.uri.c_str ();
 
@@ -205,10 +203,10 @@ void Env::buildEnvironmentString (HttpThreadContext* td, 
char *cgiEnv,
   reqEntry = td->request.other.get ("content-type");
 
   if (reqEntry)
-  {
-    memCgi << end_str << "CONTENT_TYPE=";
-    memCgi << reqEntry->value.c_str ();
-  }
+    {
+      memCgi << end_str << "CONTENT_TYPE=";
+      memCgi << reqEntry->value.c_str ();
+    }
 
   buildHttpHeaderEnvString (memCgi, td->request);
 
@@ -221,30 +219,30 @@ void Env::buildEnvironmentString (HttpThreadContext* td, 
char *cgiEnv,
 
 /*!
   Append to the environment string variables from the HTTP request header.
- */
+*/
 void Env::buildHttpHeaderEnvString (MemBuf& memCgi, HttpRequestHeader & req)
 {
 
   HashMap<string, HttpRequestHeader::Entry*>::Iterator it = req.begin ();
   for (; it != req.end (); it++)
-  {
-    HttpRequestHeader::Entry* en = *it;
-    string name;
-
-    name.assign ("HTTP_");
-    name.append (en->name.c_str ());
-    transform (name.begin ()+5, name.end (), name.begin ()+5, ::toupper);
-    for (int i = name.length (); i > 5; i--)
-      if (name[i] == '-')
-        name[i] = '_';
-
-    memCgi  << end_str << name.c_str () << "=" << en->value.c_str ();
-  }
+    {
+      HttpRequestHeader::Entry* en = *it;
+      string name;
+
+      name.assign ("HTTP_");
+      name.append (en->name.c_str ());
+      transform (name.begin ()+5, name.end (), name.begin ()+5, ::toupper);
+      for (int i = name.length (); i > 5; i--)
+        if (name[i] == '-')
+          name[i] = '_';
+
+      memCgi  << end_str << name.c_str () << "=" << en->value.c_str ();
+    }
 }
 
 /*!
   Append to the environment string process env variables.
- */
+*/
 void Env::buildProcessEnvString (MemBuf& memCgi)
 {
 #ifdef WIN32
@@ -254,13 +252,13 @@ void Env::buildProcessEnvString (MemBuf& memCgi)
   memCgi << end_str;
   if (lpvEnv)
     for (lpszVariable = (LPTSTR) lpvEnv; *lpszVariable; lpszVariable++)
-    {
-      if (((char*)lpszVariable)[0]  != '=' )
       {
-        memCgi << (char*)lpszVariable << end_str;
+        if (((char*)lpszVariable)[0]  != '=' )
+          {
+            memCgi << (char*)lpszVariable << end_str;
+          }
+        while (*lpszVariable)
+          *lpszVariable++;
       }
-      while (*lpszVariable)
-        *lpszVariable++;
-    }
 #endif
 }
diff --git a/myserver/src/protocol/http/http_data_read.cpp 
b/myserver/src/protocol/http/http_data_read.cpp
index ecbf056..49eeaa5 100644
--- a/myserver/src/protocol/http/http_data_read.cpp
+++ b/myserver/src/protocol/http/http_data_read.cpp
@@ -74,7 +74,6 @@ int HttpDataRead::readContiguousPrimitivePostData (const 
char* inBuffer,
     return 0;
 
   ret = inSocket->recv (outBuffer + *nbr,  outBufferSize - *nbr, 0, timeout);
-
   if (ret == -1)
     return -1;
 
@@ -306,6 +305,7 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
       return 1;
     }
 
+  /* It is used only when content-length is specified.  */
   length = contentLength;
 
   bufferDataSize = (td->nBytesToRead < td->buffer->getRealLength () - 1
@@ -315,7 +315,7 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
   /* If it is specified a transfer encoding read data using it.  */
   if (encoding)
     {
-      if (!encoding->value.compare ("chunked"))
+      if (encoding->value.compare ("chunked") == 0)
         {
           int ret = readChunkedPostData (td->request.uriOptsPtr,
                                          &inPos,
@@ -328,7 +328,7 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
                                          &(td->inputData),
                                          0);
 
-          if (ret == -1)
+          if (ret < 0)
             {
               td->inputData.close ();
               return -1;
@@ -350,10 +350,11 @@ int HttpDataRead::readPostData (HttpThreadContext* td, 
int* httpRetCode)
     {
       for (;;)
         {
-
           /* Do not try to read more than what we expect.  */
-          u_long dimBuffer = std::min (td->auxiliaryBuffer->getRealLength () - 
1ul,
-                                       length);
+          u_long dimBuffer = td->auxiliaryBuffer->getRealLength () - 1ul;
+
+          if (contentLengthSpecified && length < dimBuffer)
+            dimBuffer = length;
 
           if (readContiguousPrimitivePostData (td->request.uriOptsPtr,
                                                &inPos,
@@ -369,13 +370,16 @@ int HttpDataRead::readPostData (HttpThreadContext* td, 
int* httpRetCode)
               return 1;
             }
 
-          if (nbr <= length)
-            length -= nbr;
-          else
+          if (contentLengthSpecified)
             {
-              td->inputData.close ();
-              *httpRetCode = 400;
-              return 1;
+              if (nbr <= length)
+                length -= nbr;
+              else
+                {
+                  td->inputData.close ();
+                  *httpRetCode = 400;
+                  return 1;
+                }
             }
 
           td->auxiliaryBuffer->getBuffer ()[nbr] = '\0';
@@ -387,7 +391,8 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
               return -1;
             }
 
-          if (!length)
+          if ((contentLengthSpecified && length == 0)
+              || (!contentLengthSpecified && nbr == 0))
             break;
         }
     }



commit 0fafdf621cd32cd452074721d8dc3860c4aa7007
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Jun 23 16:45:57 2010 +0200

    Open the STDIN file for CGI in read only mode.

diff --git a/myserver/src/http_handler/cgi/cgi.cpp 
b/myserver/src/http_handler/cgi/cgi.cpp
index d355a21..2ca9359 100644
--- a/myserver/src/http_handler/cgi/cgi.cpp
+++ b/myserver/src/http_handler/cgi/cgi.cpp
@@ -76,6 +76,7 @@ int Cgi::send (HttpThreadContext* td, const char* scriptpath,
     to get other params like in a POST request.
   */
   Pipe stdOutFile;
+  File stdInFile;
   int len = strlen (cgipath);
   int i;
 
@@ -222,34 +223,27 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
       spi.cmdLine = cmdLine.str ();
       spi.cwd.assign (td->scriptDir);
 
-      spi.gid = atoi (td->securityToken.getData ("cgi.gid", 
MYSERVER_VHOST_CONF |
-                                                 MYSERVER_MIME_CONF |
-                                                 MYSERVER_SECURITY_CONF |
-                                                 MYSERVER_SERVER_CONF, "0"));
-      spi.uid = atoi (td->securityToken.getData ("cgi.uid", 
MYSERVER_VHOST_CONF |
-                                                 MYSERVER_MIME_CONF |
-                                                 MYSERVER_SECURITY_CONF |
-                                                 MYSERVER_SERVER_CONF, "0"));
-      spi.chroot.assign (td->securityToken.getData ("cgi.chroot", 
MYSERVER_VHOST_CONF |
-                                                    MYSERVER_MIME_CONF |
-                                                    MYSERVER_SECURITY_CONF |
-                                                    MYSERVER_SERVER_CONF, ""));
-
+      spi.gid = atoi (td->securityToken.getData ("cgi.gid", MYSERVER_VHOST_CONF
+                                                 | MYSERVER_MIME_CONF
+                                                 | MYSERVER_SECURITY_CONF
+                                                 | MYSERVER_SERVER_CONF, "0"));
+      spi.uid = atoi (td->securityToken.getData ("cgi.uid", MYSERVER_VHOST_CONF
+                                                 | MYSERVER_MIME_CONF
+                                                 | MYSERVER_SECURITY_CONF
+                                                 | MYSERVER_SERVER_CONF, "0"));
+      spi.chroot.assign (td->securityToken.getData ("cgi.chroot", 
MYSERVER_VHOST_CONF
+                                                    | MYSERVER_MIME_CONF
+                                                    | MYSERVER_SECURITY_CONF
+                                                    | MYSERVER_SERVER_CONF, 
""));
+
+      stdInFile.openFile (td->inputData.getFilename (), File::READ);
+
+      spi.stdIn = (FileHandle) stdInFile.getHandle ();
       spi.stdError = (FileHandle) stdOutFile.getWriteHandle ();
-      spi.stdIn = (FileHandle) td->inputData.getHandle ();
       spi.stdOut = (FileHandle) stdOutFile.getWriteHandle ();
       spi.envString = td->auxiliaryBuffer->getBuffer ();
 
-      if (spi.stdError == (FileHandle) -1 ||
-          spi.stdOut == (FileHandle) -1)
-        {
-          td->connection->host->warningsLogWrite (_("Cgi: internal error"));
-          stdOutFile.close ();
-          chain.clearAllFilters ();
-          return td->http->raiseHTTPError (500);
-        }
-
-      /* Execute the CGI process. */
+      /* Execute the CGI process.  */
       if (Process::getForkServer ()->isInitialized ())
         {
           int pid;
@@ -262,7 +256,7 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
       else
         cgiProc.exec (&spi);
 
-      /* Close the write stream of the pipe on the server.  */
+      stdInFile.close ();
       stdOutFile.closeWrite ();
 
       sendData (td, stdOutFile, chain, cgiProc, onlyHeader, nph);
@@ -270,13 +264,12 @@ int Cgi::send (HttpThreadContext* td, const char* 
scriptpath,
       stdOutFile.close ();
       cgiProc.terminateProcess ();
       chain.clearAllFilters ();
-
-      cgiProc.terminateProcess ();
     }
   catch (exception & e)
     {
       td->connection->host->warningsLogWrite (_E ("Cgi: internal error"), &e);
       stdOutFile.close ();
+      stdInFile.close ();
       chain.clearAllFilters ();
       return td->http->raiseHTTPError (500);
     }



commit 2eab3e3fed1ddd84bb877c7eb737e4702d60ee06
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Jun 23 16:45:18 2010 +0200

    When creating a temporary file, don't attempt to delete it before.

diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 6244655..106422b 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -148,7 +148,7 @@ int File::openFile (const char* nfilename, u_long opt, 
mode_t mask)
     flags = O_WRONLY;
 
   if (opt & File::NO_FOLLOW_SYMLINK)
-    flags = O_NOFOLLOW;
+    flags |= O_NOFOLLOW;
 
   if (opt & File::APPEND)
     flags |= O_APPEND;
@@ -240,12 +240,9 @@ const char *File::getFilename ()
  */
 int File::createTemporaryFile (const char* filename, bool unlink)
 {
-  if (FilesUtility::nodeExists (filename))
-    FilesUtility::deleteFile (filename);
-
   u_long temporaryOpt = unlink ? File::TEMPORARY : File::TEMPORARY_DELAYED;
 
-  return openFile (filename, File::READ | File::WRITE | File::NO_INHERIT
+  return openFile (filename, File::READ | File::WRITE
                    | File::FILE_OPEN_ALWAYS | temporaryOpt);
 }
 



commit d05067a9f29fa83925d215eaf7d9b44957dbeaa3
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Jun 23 16:44:06 2010 +0200

    Do not close standard descriptors.

diff --git a/myserver/src/base/process/process.cpp 
b/myserver/src/base/process/process.cpp
index c4bacb8..9c1b97a 100644
--- a/myserver/src/base/process/process.cpp
+++ b/myserver/src/base/process/process.cpp
@@ -262,34 +262,31 @@ int Process::exec (StartProcInfo* spi, bool waitEnd)
       if (generateEnvString (envp, size, (char*) spi->envString))
         exit (1);
 
-      if (spi->cwd.length ()
-          && chdir (spi->cwd.c_str ()) == -1)
+      if (spi->cwd.length () && chdir (spi->cwd.c_str ()) == -1)
         exit (1);
 
-      if ((long)spi->stdOut == -1)
-        spi->stdOut = checked::open ("/dev/null", O_WRONLY);
+      if (spi->stdIn < 0)
+        gnulib::close (0);
+      else
+        checked::dup2 (spi->stdIn, 0);
 
-      if ((long)spi->stdError == -1)
-        spi->stdError = checked::open ("/dev/null", O_WRONLY);
+      if (spi->stdOut < 0)
+        gnulib::close (1);
+      else
+        checked::dup2 (spi->stdOut, 1);
 
-      checked::close (0);
+      if (spi->stdError < 0)
+        gnulib::close (2);
+      else
+        checked::dup2 (spi->stdError, 2);
 
-      if (spi->stdIn != -1)
-        {
-          if (checked::dup2 (spi->stdIn, 0) == -1)
-            exit (1);
-          checked::close (spi->stdIn);
-        }
-
-      checked::close (1);
 
-      if (checked::dup2 (spi->stdOut, 1) == -1)
-        exit (1);
-
-      checked::close (2);
-
-      if (checked::dup2 (spi->stdError, 2) == -1)
-        exit (1);
+      if (spi->stdIn < 0)
+        gnulib::close (spi->stdIn);
+      if (spi->stdOut < 0)
+        gnulib::close (spi->stdOut);
+      if (spi->stdError < 0)
+        gnulib::close (spi->stdError);
 
       if (spi->handlesToClose)
         {
@@ -304,7 +301,7 @@ int Process::exec (StartProcInfo* spi, bool waitEnd)
       execve ((const char*) args[0],
               (char* const*) args, (char* const*) envp);
 
-    exit (1);
+      exit (1);
   }
 
   if (waitEnd)

-----------------------------------------------------------------------

Summary of changes:
 myserver/src/base/file/file.cpp               |    7 +-
 myserver/src/base/process/process.cpp         |   43 ++++----
 myserver/src/http_handler/cgi/cgi.cpp         |   47 ++++-----
 myserver/src/protocol/http/env/env.cpp        |  134 ++++++++++++-------------
 myserver/src/protocol/http/http_data_read.cpp |   31 ++++---
 5 files changed, 126 insertions(+), 136 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]