[Spice-devel] [PATCH 2/2] Don't truncate SPICE_FOREIGN_MENU_SOCKET

Christophe Fergeau cfergeau at redhat.com
Tue Mar 20 08:14:08 PDT 2012


When we get the socket name for the foreign menu socket from
an environment variable, we cannot make assumptions about its length.
Currently, we are strncpying to a 50 byte buffer which is easily
too small.
---
 client/foreign_menu.cpp |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/client/foreign_menu.cpp b/client/foreign_menu.cpp
index 1010bfb..70b6dc2 100644
--- a/client/foreign_menu.cpp
+++ b/client/foreign_menu.cpp
@@ -46,13 +46,16 @@ ForeignMenu::ForeignMenu(ForeignMenuInterface *handler, bool active)
     ASSERT(_handler != NULL);
 #ifndef WIN32
     const char *p_socket = getenv("SPICE_FOREIGN_MENU_SOCKET");
-    if (p_socket)
-        strncpy(pipe_name, p_socket, sizeof(pipe_name));
-    else
+    if (p_socket) {
+        LOG_INFO("Creating a foreign menu connection %s", p_socket);
+        _foreign_menu = NamedPipe::create(p_socket, *this);
+    } else
 #endif
+    {
         snprintf(pipe_name, PIPE_NAME_MAX_LEN, PIPE_NAME, Platform::get_process_id());
-    LOG_INFO("Creating a foreign menu connection %s", pipe_name);
-    _foreign_menu = NamedPipe::create(pipe_name, *this);
+        LOG_INFO("Creating a foreign menu connection %s", pipe_name);
+        _foreign_menu = NamedPipe::create(pipe_name, *this);
+    }
     if (!_foreign_menu) {
         LOG_ERROR("Failed to create a foreign menu connection");
     }
-- 
1.7.7.6



More information about the Spice-devel mailing list