1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* gcc test-wm-class.c -o test-wm-class -lX11 */
/* Normally you'd use XSetClassHint() to set WM_CLASS, which ensures
that it consists of 2 null terminated strings, but some applications don't
and we must handle malformed WM_CLASS safely */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
Display *d;
void test(unsigned char *buffer, unsigned int buffer_length)
{
Window w;
w = XCreateWindow(d, RootWindow(d, DefaultScreen(d)), 0, 0, 200, 200, 0,
CopyFromParent, InputOutput, CopyFromParent, 0, 0);
Atom wm_class = XInternAtom(d, "WM_CLASS", False);
XChangeProperty(d, w, wm_class, XA_STRING, 8, PropModeReplace, buffer, buffer_length);
XMapWindow(d, w);
XFlush(d);
sleep(1);
}
int main(int argc, char **argv)
{
d = XOpenDisplay(0);
test("", 0);
test("\0", 1);
test("\0\0", 2);
test("foo", 3);
test("foo\0", 4);
test("foo\0b", 5);
test("foo\0bar", 7);
test("foo\0bar\0", 8);
while(1) sleep(1);
}
|