Re: [dev] [dwm] [PATCH] NULL byte in WM_NAME

From: Laslo Hunhold <dev_AT_frign.de>
Date: Tue, 26 Dec 2017 20:03:21 +0100

On Tue, 26 Dec 2017 13:28:34 +0100
Kernc <kerncece_AT_gmail.com> wrote:

Hey Kernc,

> dwm 6.1-3 on ArchLinux sets WM_NAME hint on one of its windows to:
>
> "dwm\0"
>
> (with \0 being a null byte). Not certain of this, but it's what
> xwininfo reports:
>
> $ xwininfo -root -all
> Root window id: 0x126 (the root window) " X 62% | us | 59°C |
> 0.31 | 3725MB | ac 100% | Dec 26 12:42 "
> Parent window id: 0x0 (none)
> 42 children:
> ...
> 0xa0001e "dwm^_AT_": () 1x1+0+0 +0+0
> 0xa0000d (has no name): ("dwm" "dwm") 2560x19+0+0 +0+0
> ...
>
> (^_AT_ is null character in caret notation.)
>
> This makes a particular program that uses libwnck [1] fail after:
>
> Wnck-WARNING **: Property _NET_WM_NAME contained invalid UTF-8
>
> in this code [2] because the returned string contains a '\0' and the
> documentation for g_utf8_validate() [3] explicitly states that when
> string length is provided, no nul bytes are allowed.
>
> Maybe libwnck's atom string handling should be more robust, but
> since no other window ever seems to do this, I dare ask:
>
> *Why* does dwm set the title on one of its windows to "dwm\0" ?

first off, thank you very much for this well-written report! I'm sure
everyone agrees that more should start like this; it saves everyone
involved in reading a good amount of time.

The problem itself seems like a trivial matter, and from what I see,
we should change the constant 4 in [0] to 3. I personally don't care
about libwnck to be honest, however, what convinces me is what xwininfo
puts in its output.

In a more philosophical sense: The NUL-byte is just a form of
termination for strings in memory. When we carry around the explicit
length of the string anyway, there's no reason to carry around the
NUL-byte as well.
Maybe it was set this way in the first place to prevent possible
accidents from happening, like somebody using XGetProperty and
forgetting that the given string is not NUL-terminated or something.
However, I generally do not support this kind of pre-thought, as any
tool containing this bug would break on any other wm which does not
NUL-terminate its name in the X-property.

The only thing missing from this report was a patch, which I attached.

With best regards

Laslo Hunhold

[0]: https://git.suckless.org/dwm/tree/dwm.c#n1582

-- 
Laslo Hunhold <dev_AT_frign.de>
Received on Tue Dec 26 2017 - 20:03:21 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 26 2017 - 20:12:19 CET