! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Xfwm has a hard limit of 31 character hostnames.
Status:
RESOLVED: FIXED

Comments

Description Alistair Buxton 2014-11-05 20:58:26 CET
Created attachment 5727 
Determine max hostname

In display.c:

#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:

https://bugzilla.redhat.com/show_bug.cgi?id=1085082

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.
Comment 1 Alistair Buxton 2014-11-06 13:43:58 CET
In order to test this you need a program which doesn't respond to NET_WM_PING.

A suitable test application is available here:

https://maemo.gitorious.org/fremantle-hildon-desktop/hildon-desktop/source/1be6ec951a4eed1d79878f88d2eacb298b447112:tests/test-hung-process.c

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.
Comment 2 Simon Steinbeiss editbugs 2014-11-07 11:26:43 CET
Thanks for the patch, I just verified your testcase here.
Pushed to master: http://git.xfce.org/xfce/xfwm4/commit/?id=19e9cc2db222fde7f138de86f3cedcda4a4d4295

Bug #11282

Reported by:
Alistair Buxton
Reported on: 2014-11-05
Last modified on: 2014-11-07

People

Assignee:
Olivier Fourdan
CC List:
1 user

Version

Version:
unspecified

Attachments

Determine max hostname (2.13 KB, patch)
2014-11-05 20:58 CET , Alistair Buxton
no flags

Additional information