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. d045b54be1


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. d045b54be1eabae67ba544470c2bd7ae583e6233
Date: Tue, 18 Aug 2009 22:11:57 +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  d045b54be1eabae67ba544470c2bd7ae583e6233 (commit)
      from  ab546da121d89d2fb8f74727080cd5dfeb4b7b84 (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 d045b54be1eabae67ba544470c2bd7ae583e6233
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Aug 19 00:10:24 2009 +0200

    Check for the array dimension used by Process::generateEnvString before 
access it.

diff --git a/myserver/include/base/process/process.h 
b/myserver/include/base/process/process.h
index e50ba79..db0ea34 100755
--- a/myserver/include/base/process/process.h
+++ b/myserver/include/base/process/process.h
@@ -40,17 +40,17 @@ struct StartProcInfo
   }
 
        /*! STDIN file for new process.  */
-       FileHandle stdIn;       
-       
+       FileHandle stdIn;
+
        /*! STDOUT file for new process.  */
        FileHandle stdOut;
-       
+
        /*! STDERR file for new process.  */
        FileHandle stdError;
-       
+
        string cmdLine;
        string cwd;
-       
+
        /*! added for unix support.  */
        string cmd;
        string arg;
@@ -63,9 +63,9 @@ struct StartProcInfo
 
        void *envString;
 
-  /*! Pointer to a NULL terminated array of 
+  /*! Pointer to a NULL terminated array of
    *  file pointers to close.  */
-  FileHandle *handlesToClose; 
+  FileHandle *handlesToClose;
 };
 
 class Process
@@ -96,8 +96,10 @@ public:
   static uid_t getUid (const char *user);
   static gid_t getGid (const char *group);
 
-  static int generateEnvString (const char **envp, char *envString);
-  static int generateArgList (const char **args, const char *proc, string 
&additionalArgs);
+  static int generateEnvString (const char **envp, size_t size,
+                                char *envString);
+  static int generateArgList (const char **args, size_t size, const char *proc,
+                              string &additionalArgs);
 
   static ForkServer *getForkServer (){return &forkServer;}
 private:
diff --git a/myserver/src/base/process/process.cpp 
b/myserver/src/base/process/process.cpp
index db6a2f5..e10f544 100755
--- a/myserver/src/base/process/process.cpp
+++ b/myserver/src/base/process/process.cpp
@@ -19,25 +19,26 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include "stdafx.h"
 #include <include/base/utility.h>
 
-extern "C" {
+extern "C"
+{
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 
 #ifndef WIN32
-#include <unistd.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
+# include <unistd.h>
+# include <signal.h>
+# include <sys/types.h>
+# include <sys/wait.h>
 
-#ifdef GETPWNAM
-#include <pwd.h>
-#endif
+# ifdef GETPWNAM
+#  include <pwd.h>
+# endif
 
-#ifdef GRP
-#include <grp.h>
-#endif
+# ifdef GRP
+#  include <grp.h>
+# endif
 
 #endif
 }
@@ -69,15 +70,17 @@ Mutex Process::forkMutex;
 ForkServer Process::forkServer;
 
 /*!
- *Generate the arguments vector for execve.
- *\param args The output arguments vector to fill.
- *\param proc The executable.
- *\param additionalArgs additional arguments.
+ * Generate the arguments vector for execve.
+ * \param args The output arguments vector to fill.
+ * \param size Size of the args vector.
+ * \param proc The executable.
+ * \param additionalArgs additional arguments.
  */
-int Process::generateArgList (const char **args, const char *proc, string 
&additionalArgs)
+int Process::generateArgList (const char **args, size_t size, const char *proc,
+                              string &additionalArgs)
 {
   args[0] = proc;
-  
+
   const char *arg = additionalArgs.c_str ();
   int count = 1;
   int len = additionalArgs.length ();
@@ -95,7 +98,7 @@ int Process::generateArgList (const char **args, const char 
*proc, string &addit
           if (i == len)
             exit(1);
 
-          if (count < 100)
+          if (count < size)
             {
               args[count++] = &(additionalArgs[start + 1]);
               start = i + 1;
@@ -108,7 +111,7 @@ int Process::generateArgList (const char **args, const char 
*proc, string &addit
         {
           if (i - start <= 1)
             continue;
-          if (count < 100)
+          if (count < size)
             {
               args[count++] = &(additionalArgs[start]);
               additionalArgs[i] = '\0';
@@ -122,7 +125,7 @@ int Process::generateArgList (const char **args, const char 
*proc, string &addit
             break;
         }
     }
-  if (count < 100 && len != start)
+  if (count < size && len != start)
     {
       args[count++] = &(additionalArgs[start]);
     }
@@ -134,15 +137,15 @@ int Process::generateArgList (const char **args, const 
char *proc, string &addit
 
 
 /*!
- *Generate the env array for execve.
- *\param envp Enviroment variables array.
- *\param envString Enviroment values separed by the NULL character.
+ * Generate the env array for execve.
+ * \param envp Enviroment variables array.
+ * \param size Size of the args vector.
+ * \param envString Enviroment values separed by the NULL character.
  */
-int Process::generateEnvString (const char **envp, char *envString)
+int Process::generateEnvString (const char **envp, size_t size, char 
*envString)
 {
   int i = 0;
-  int index = 0;
- 
+  size_t index = 0;
 
   if (envString != NULL)
     {
@@ -150,8 +153,11 @@ int Process::generateEnvString (const char **envp, char 
*envString)
         {
           envp[index] = envString + i;
           index++;
-          
-          while(*(envString + i++) != '\0');
+
+          if (index == size)
+            return 1;
+
+          while (*(envString + i++) != '\0');
         }
       envp[index] = NULL;
     }
@@ -160,18 +166,16 @@ int Process::generateEnvString (const char **envp, char 
*envString)
   return 0;
 }
 
-
-
 /*!
- *Spawn a new process.
+ * Spawn a new process.
  *
- *\param spi new process information.
- *\param waitEnd Specify if wait until the process finishes.
+ * \param spi new process information.
+ * \param waitEnd Specify if wait until the process finishes.
  *
- *\return -1 on failure.
- *\return the new process identifier on success.
+ * \return -1 on failure.
+ * \return the new process identifier on success.
  */
-int Process::exec(StartProcInfo* spi, bool waitEnd)
+int Process::exec (StartProcInfo* spi, bool waitEnd)
 {
   pid = 0;
 #ifdef WIN32
@@ -201,9 +205,6 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
 
   if (waitEnd)
     {
-      /*
-       *Wait until the process stops its execution.
-       */
       ret = WaitForSingleObject (pi.hProcess, INFINITE);
 
       if (ret == WAIT_FAILED)
@@ -222,14 +223,14 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
 #ifndef WIN32
   pid = fork ();
 
-  if (pid < 0) // a bad thing happened
+  if (pid < 0)
     return 0;
 
-  if (pid == 0) // child
+  if (pid == 0)
     {
-      // Set env vars
-      const char *envp[100];
-      const char *args[100];
+      const size_t size = 100;
+      const char *envp[size];
+      const char *args[size];
 
       if (spi->gid.length ())
         Process::setgid (spi->gid.c_str ());
@@ -237,19 +238,16 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
       if (spi->uid.length ())
         Process::setuid (spi->uid.c_str ());
 
-      if (generateArgList (args, spi->cmd.c_str (), spi->arg))
+      if (generateArgList (args, size, spi->cmd.c_str (), spi->arg))
         exit (1);
 
-      if (generateEnvString (envp, (char*) spi->envString))
+      if (generateEnvString (envp, size, (char*) spi->envString))
         exit (1);
-      
-      // change to working dir
-      if (spi->cwd.length ())
-        {
-          if (chdir ((const char*)(spi->cwd.c_str())) == -1)
-            exit (1);
-        }
- 
+
+      if (spi->cwd.length ()
+          && chdir ((const char*)(spi->cwd.c_str())) == -1)
+        exit (1);
+
       if ((long)spi->stdOut == -1)
         spi->stdOut = (FileHandle)open ("/dev/null", O_WRONLY);
 
@@ -275,7 +273,7 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
 
       if (dup2 (spi->stdError, 2) == -1)
         exit (1);
-      
+
       if (spi->handlesToClose)
         {
           FileHandle* h = spi->handlesToClose;
@@ -286,7 +284,7 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
             }
         }
 
-      execve ((const char*)args[0], 
+      execve ((const char*)args[0],
               (char* const*)args, (char* const*) envp);
 
     exit (1);
@@ -294,9 +292,7 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
   }
 
   if (waitEnd)
-    {
-      return waitpid(pid, NULL, 0);
-    }
+    return waitpid (pid, NULL, 0);
   else
     return pid;
 
@@ -306,8 +302,8 @@ int Process::exec(StartProcInfo* spi, bool waitEnd)
 }
 
 /*!
- *Get an uid given a username.
- *\param the user name to convert.
+ * Get an uid given a username.
+ * \param the user name to convert.
  */
 uid_t Process::getUid (const char *user)
 {
@@ -333,8 +329,8 @@ uid_t Process::getUid (const char *user)
 }
 
 /*!
- *Get an uid given a username.
- *\param the user name to convert.
+ * Get an uid given a username.
+ * \param the user name to convert.
  */
 gid_t Process::getGid (const char *grp)
 {
@@ -359,8 +355,8 @@ gid_t Process::getGid (const char *grp)
 }
 
 /*!
- *Return a nonzero value if the process is still alive. A return value of zero
- *means the process is a zombie.
+ * Return a nonzero value if the process is still alive. A return value of zero
+ * means the process is a zombie.
  */
 int Process::isProcessAlive ()
 {
@@ -389,7 +385,7 @@ int Process::isProcessAlive ()
     return 1;
   return 0;
 #else
-  /*! Send the pseudo-signal 0 to check if the process is alive.  */
+  /* Send the pseudo-signal 0 to check if the process is alive.  */
   int ret;
   do
   {
@@ -399,7 +395,7 @@ int Process::isProcessAlive ()
   if (ret == 0)
     return 1;
 
-  /*! Waitpid it to free the resource.  */
+  /* Waitpid it to free the resource.  */
   waitpid (pid, &status, WNOHANG | WUNTRACED);
 
   return 0;
@@ -412,7 +408,7 @@ int Process::isProcessAlive ()
 #ifdef HAVE_PTHREAD
 
 /*!
- *Called in the parent before do a fork.
+ * Called in the parent before do a fork.
  */
 void Process::forkPrepare ()
 {
@@ -420,7 +416,7 @@ void Process::forkPrepare ()
 }
 
 /*!
- *Called in the parent after the fork.
+ * Called in the parent after the fork.
  */
 void Process::forkParent ()
 {
@@ -428,16 +424,16 @@ void Process::forkParent ()
 }
 
 /*!
- *Called in the child process after the fork.
+ * Called in the child process after the fork.
  */
 void Process::forkChild ()
 {
-  forkMutex.unlock ();  
+  forkMutex.unlock ();
 }
 #endif
 
 /*!
- *Initialize the static process data.
+ * Initialize the static process data.
  */
 void Process::initialize ()
 {
@@ -448,7 +444,7 @@ void Process::initialize ()
 }
 
 /*!
- *Create the object.
+ * Create the object.
  */
 Process::Process ()
 {
@@ -456,7 +452,7 @@ Process::Process ()
 }
 
 /*!
- *Destroy the object.
+ * Destroy the object.
  */
 Process::~Process ()
 {
@@ -464,9 +460,9 @@ Process::~Process ()
 }
 
 /*!
- *Terminate a process.
- *Return 0 on success.
- *Return nonzero on fails.
+ * Terminate a process.
+ * Return 0 on success.
+ * Return nonzero on fails.
  */
 int Process::terminateProcess ()
 {
@@ -486,7 +482,7 @@ int Process::terminateProcess ()
 }
 
 /*!
- *Set the user identity for the process. Returns 0 on success.
+ * Set the user identity for the process. Returns 0 on success.
  */
 int Process::setuid (const char *uid)
 {
@@ -498,7 +494,7 @@ int Process::setuid (const char *uid)
 }
 
 /*!
- *Set the group identity for the process. Returns 0 on success.
+ * Set the group identity for the process. Returns 0 on success.
  */
 int Process::setgid (const char *gid)
 {
@@ -510,7 +506,7 @@ int Process::setgid (const char *gid)
 }
 
 /*!
- *Set the additional groups list for the process.
+ * Set the additional groups list for the process.
  */
 int Process::setAdditionalGroups (u_long len, u_long *groups)
 {
@@ -520,7 +516,7 @@ int Process::setAdditionalGroups (u_long len, u_long 
*groups)
   u_long i;
   int ret;
   gid_t *gids = new gid_t[len];
-  
+
   for (i = 0; i < len; i++)
     if (groups)
       gids[i] = (gid_t)groups[i];
diff --git a/myserver/src/base/thread/thread.cpp 
b/myserver/src/base/thread/thread.cpp
index b3416ef..4ccf80c 100755
--- a/myserver/src/base/thread/thread.cpp
+++ b/myserver/src/base/thread/thread.cpp
@@ -41,11 +41,11 @@ extern "C"
 #include <sys/types.h>
 
 #ifdef WIN32
-#include <direct.h>
+# include <direct.h>
 #endif
 
 /*!
- *Sleep the caller thread for [TIME] microseconds.
+ * Sleep the caller thread for [TIME] microseconds.
  */
 void Thread::wait (u_long time)
 {

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

Summary of changes:
 myserver/include/base/process/process.h |   20 ++--
 myserver/src/base/process/process.cpp   |  158 +++++++++++++++----------------
 myserver/src/base/thread/thread.cpp     |    4 +-
 3 files changed, 90 insertions(+), 92 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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