Subject: Re: [X2Go-Dev] Bug#516: [PATCH 1/5] Create Windows on Big Endian 64bit systems

From: Mihai Moldovan <[email-masked]>
Date: Sat, 21 Jun 2014 05:15:43 +0200

An endiannes issue was setting incorrect event masks when creating X11 windows.

This time, a smaller integer has been casted to a bigger one and passed to some
function actually setting its value.

This meant, that garbage from stack was attached to the smaller integer value,
putting unknown memory into the lower bytes of the bigger integer.

Fix this by creating a big, initialized temporary variable, let the function do
its magic on that one and pass the value back to the smaller variable -- and
cross your fingers the smaller variable can hold it without overrunning. (The
last bit is a design issue we can't really fix and has been around even before
this patch.)

Mihai
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c
index 0a8e8c2..3603a05 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Window.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c
@@ -335,7 +335,10 @@ FIXME: We need to set save under on the real display?
 
   if (mask & CWEventMask)
   {
-    nxagentGetEventMask(pWin, (Mask*)&attributes.event_mask);
+    /* Assume that the mask fits in int... broken on Big Endian 64bit systems. */
+    Mask tmp_mask = attributes.event_mask;
+    nxagentGetEventMask(pWin, &tmp_mask);
+    attributes.event_mask = (int)tmp_mask;
   }
   #ifdef WARNING
   else