From 64e0974114e4b7e5d737fdf1c19338751064fd0d Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Tue, 20 Mar 2012 16:07:22 +0100 Subject: Don't truncate SPICE_FOREIGN_MENU_SOCKET 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 file changed, 8 insertions(+), 5 deletions(-) (limited to 'client') diff --git a/client/foreign_menu.cpp b/client/foreign_menu.cpp index 1010bfba..70b6dc23 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"); } -- cgit