From cadc4d801c038bf441e7f22ee0d88110b09d3b57 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Perrier Date: Fri, 22 May 2015 15:11:14 +0200 Subject: [PATCH] Fix undefined behavior in ewmhSupported() caused by some window managers not null-terminating strings. Fixes #892 --- src/SFML/Window/Unix/WindowImplX11.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 7d8f984ab..8387975c6 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -235,9 +235,12 @@ namespace sf::priv::CloseConnection(connection); - const char* name = reinterpret_cast(xcb_get_property_value(wmName.get())); - - windowManagerName = name; + // It seems the wm name string reply is not necessarily + // null-terminated. The work around is to get its actual + // length to build a proper string + const char* begin = reinterpret_cast(xcb_get_property_value(wmName.get())); + const char* end = begin + xcb_get_property_value_length(wmName.get()); + windowManagerName = sf::String::fromUtf8(begin, end); return true; }