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.
This commit is contained in:
Christophe Fergeau 2012-03-20 16:07:22 +01:00
parent 3d452a312b
commit 64e0974114

View File

@ -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");
}