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

git-admin at x2go.org git-admin at x2go.org
Wed Jan 13 18:41:30 CET 2016


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

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

commit 6a71e67acbd8f946e6209e76c2c2a5699c15f0aa
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 7b69494..058d32c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -52,6 +52,9 @@ x2goclient (4.0.5.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.)
   * debian/control:
     - Change apache2-dev | libc6-dev build dependency back to apache2-dev
       only. Otherwise, apache2-dev is not installed at all, even though
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