[X2Go-Commits] [x2goclient] 21/44: x2goclient.cpp: create new argv array on the heap instead of on the stack.

git-admin at x2go.org git-admin at x2go.org
Mon Jun 29 23:02:12 CEST 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch bugfix/osx
in repository x2goclient.

commit 2d0ba031fb34a2d56b260ed45be9d473c9d3c65a
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Mar 18 05:51:03 2015 +0100

    x2goclient.cpp: create new argv array on the heap instead of on the stack.
    
    Stack data will be invalid once the function goes out of scope (which is
    what execv is doing.)
---
 debian/changelog   |    3 +++
 src/x2goclient.cpp |   12 ++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6e86e26..529614a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -98,6 +98,9 @@ x2goclient (4.0.4.1-0x2go1) UNRELEASED; urgency=low
       after fork on virtually all operating system, especially on OS X.
     - x2goclient.cpp: fix compile problems introduced with the last commit.
     - x2goclient.cpp: fix string comparison.
+    - x2goclient.cpp: create new argv array on the heap instead of on the
+      stack. Stack data will be invalid once the function goes out of scope
+      (which is what execv is doing.)
 
   [ Mike Gabriel ]
   * debian/control:
diff --git a/src/x2goclient.cpp b/src/x2goclient.cpp
index c695e26..479d564 100644
--- a/src/x2goclient.cpp
+++ b/src/x2goclient.cpp
@@ -47,20 +47,20 @@ int fork_helper (int argc, char **argv) {
     new_argv.push_back (std::string (argv[0]));
     new_argv.push_back ("--unixhelper");
 
-    std::vector<char *> new_argv_c_str;
+    std::vector<char *> *new_argv_c_str = new (std::vector<char *>) ();
     for (std::vector<std::string>::iterator it = new_argv.begin (); it != new_argv.end (); ++it) {
       const char *elem = (*it).c_str ();
-      new_argv_c_str.push_back (strndup (elem, std::strlen (elem)));
+      new_argv_c_str->push_back (strndup (elem, std::strlen (elem)));
     }
 
     /* Add null pointer as last element. */
     {
-      std::vector<char> tmp;
-      tmp.push_back (0);
-      new_argv_c_str.push_back (&tmp.front ());
+      std::vector<char> *tmp = new (std::vector<char>) ();
+      tmp->push_back (0);
+      new_argv_c_str->push_back (&tmp->front ());
     }
 
-    if (0 != execv (new_argv_c_str.front (), &(new_argv_c_str.front ()))) {
+    if (0 != execv (new_argv_c_str->front (), &(new_argv_c_str->front ()))) {
       std::cerr << "Failed to re-execute process as UNIX cleanup helper tool: " << std::strerror (errno) << "\n"
                 << "Terminating and killing parent." << "\n"
                 << "Please report a bug, refer to this documentation: http://wiki.x2go.org/doku.php/wiki:bugs" << std::endl;

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list