Created attachment 5727
Determine max hostname
#define MAX_HOSTNAME_LENGTH 32
This includes the null byte, so the limit is really 31 characters. The real limit is 64+1 on Linux and 255+1 on BSD.
If the buffer is not big enough for the hostname, gethostname will return ENAMETOOLONG and the hostname will be set to NULL.
Later, when a client is killed, the hostname is tested with strcmp, which causes a segfault.
Example of the bug:
If you check the environment file posted, the hostname is 33 characters.
Patch is attached which uses HOST_NAME_MAX to determine the maximum hostname length. If not defined, it is defined to 255. From the gethostname (Linux) man page:
SUSv2 guarantees that "Host names are limited to 255 bytes".
POSIX.1-2001 guarantees that "Host names (not including the terminating
null byte) are limited to HOST_NAME_MAX bytes". On Linux,
HOST_NAME_MAX is defined with the value 64, which has been the limit
since Linux 1.0 (earlier kernels imposed a limit of 8 bytes).
The patch also adds a warning if gethostname still fails, and a null check in when the hostname is tested.
In order to test this you need a program which doesn't respond to NET_WM_PING.
A suitable test application is available here:
Compile it like this:
gcc -o test-hung-process test-hung-process.c `pkg-config --cflags --libs gtk+-2.0`
Run this command to set hostname:
sudo hostname aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Log out and log in again to update environment. (Don't restart, hostname is not saved.)
Now when you start a shell you should see your new, long, hostname.
Run the test application, and when the window opens, click the close button. After a few seconds Xfwm will ask if you want to kill it. Click "yes".
Without patch, Xfwm will segfault after you click "yes". It will then restart and the hung window will still exist.
With the patch, the process will be killed as expected, and Xfwm won't crash.
Thanks for the patch, I just verified your testcase here.
Pushed to master: http://git.xfce.org/xfce/xfwm4/commit/?id=19e9cc2db222fde7f138de86f3cedcda4a4d4295