-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path0008-Fail-safe-when-displaying-colors.patch
146 lines (139 loc) · 5.33 KB
/
0008-Fail-safe-when-displaying-colors.patch
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From 938d64572b0667775ea70b94c9bb02ff81b1fda2 Mon Sep 17 00:00:00 2001
From: Demi Marie Obenour <[email protected]>
Date: Mon, 14 Jun 2021 00:28:03 -0400
Subject: [PATCH 8/9] Fail-safe when displaying colors
If something goes wrong, display a window as red.
---
src/client.c | 86 +++++++++++++++++++++++++--------------------------
src/display.c | 4 ++-
src/display.h | 2 ++
3 files changed, 48 insertions(+), 44 deletions(-)
diff --git a/src/client.c b/src/client.c
index aa66f00..8510a2c 100644
--- a/src/client.c
+++ b/src/client.c
@@ -172,55 +172,55 @@ getQubesLabel (Client *c)
{
ScreenInfo *screen_info;
DisplayInfo *display_info;
- Atom atom_label;
- Atom atom_label_color;
screen_info = c->screen_info;
display_info = screen_info->display_info;
- atom_label = XInternAtom(display_info->dpy, "_QUBES_LABEL", TRUE);
- atom_label_color = XInternAtom(display_info->dpy, "_QUBES_LABEL_COLOR", TRUE);
-
c->qubes_label_color = QUBES_LABEL_DOM0;
- if (atom_label_color) {
- Atom actual_type;
- int actual_format;
- unsigned long nitems = 0, bytes_left;
- unsigned char *data = 0;
-
- if ((XGetWindowProperty (display_info->dpy, c->window, atom_label_color, 0L, 1L,
- FALSE, XA_CARDINAL, &actual_type, &actual_format, &nitems,
- &bytes_left, &data) == Success))
- {
- if (nitems == 1 && actual_format == 32) {
- c->qubes_label_color = *(long*)data;
- }
- }
- }
- if (c->qubes_label_color == QUBES_LABEL_DOM0 && atom_label) {
- Atom actual_type;
- int actual_format;
- unsigned long nitems = 0, bytes_left;
- char *data = 0;
-
- if ((XGetWindowProperty (display_info->dpy, c->window, atom_label, 0L, 1L,
- FALSE, AnyPropertyType, &actual_type, &actual_format, &nitems,
- &bytes_left, (unsigned char **) &data) == Success))
- {
- if (nitems != 1) {
- // ERROR? Only Dom0 Windows don't have this property set...
- c->qubes_label_color = QUBES_LABEL_DOM0;
- } else {
- int qubes_label = (int)*data;
- if (qubes_label >= 0 && qubes_label < MAX_QUBES_LABELS) {
- c->qubes_label_color = qubes_label_colors[qubes_label];
- } else {
- /* out of range?! */
- c->qubes_label_color = QUBES_LABEL_RED;
- }
- }
+ Atom actual_type;
+ int actual_format = 100;
+ unsigned long nitems = 0, bytes_left = 100;
+ unsigned char *data = 0;
+
+ if ((XGetWindowProperty (display_info->dpy, c->window,
+ display_info->atoms[QUBES_LABEL_COLOR], 0L, 1L,
+ FALSE, XA_CARDINAL, &actual_type, &actual_format,
+ &nitems, &bytes_left, &data) != Success)) {
+ g_warning("Cannot check if a window is a Qubes window");
+ c->qubes_label_color = QUBES_LABEL_RED;
+ return;
+ } else if (nitems == 1 && actual_format == 32 && bytes_left == 0 && data) {
+ c->qubes_label_color = *(long*)data;
+ XFree(data);
+ return;
+ } else if (nitems || actual_format || bytes_left || data) {
+ XFree(data);
+ g_warning("Cannot check if a window is a Qubes window");
+ c->qubes_label_color = QUBES_LABEL_RED;
+ return;
+ } else if ((XGetWindowProperty (display_info->dpy, c->window,
+ display_info->atoms[QUBES_LABEL], 0L, 1L,
+ FALSE, AnyPropertyType, &actual_type, &actual_format,
+ &nitems, &bytes_left, (unsigned char **) &data) != Success)) {
+ g_warning("Cannot get QUBES_LABEL");
+ c->qubes_label_color = QUBES_LABEL_RED;
+ } else if (!actual_type && !actual_format && !nitems && !bytes_left && !data) {
+ // Only Dom0 Windows don't have this property set...
+ c->qubes_label_color = QUBES_LABEL_DOM0;
+ } else if (nitems != 1 || bytes_left || !data || actual_type != XA_CARDINAL ||
+ actual_format != 8) {
+ XFree(data);
+ g_warning("Bogus QUBES_LABEL?");
+ c->qubes_label_color = QUBES_LABEL_RED;
+ } else {
+ int qubes_label = (int)*data;
+ XFree(data);
+ if (qubes_label >= 0 && qubes_label < MAX_QUBES_LABELS) {
+ c->qubes_label_color = qubes_label_colors[qubes_label];
} else {
- c->qubes_label_color = QUBES_LABEL_DOM0;
+ /* out of range?! */
+ g_warning("Out of range QUBES_LABEL?");
+ c->qubes_label_color = QUBES_LABEL_RED;
}
}
}
diff --git a/src/display.c b/src/display.c
index d9cca8e..f9f35cb 100644
--- a/src/display.c
+++ b/src/display.c
@@ -179,7 +179,9 @@ myDisplayInitAtoms (DisplayInfo *display_info)
"XFWM4_TIMESTAMP_PROP",
"_XROOTPMAP_ID",
"_XSETROOT_ID",
- "_GTK_READ_RCFILES"
+ "_GTK_READ_RCFILES",
+ "_QUBES_LABEL",
+ "_QUBES_LABEL_COLOR",
};
g_assert (ATOM_COUNT == G_N_ELEMENTS (atom_names));
diff --git a/src/display.h b/src/display.h
index 1d6ffe6..c872a23 100644
--- a/src/display.h
+++ b/src/display.h
@@ -272,6 +272,8 @@ enum
XROOTPMAP,
XSETROOT,
GTK_READ_RCFILES,
+ QUBES_LABEL,
+ QUBES_LABEL_COLOR,
ATOM_COUNT
};
--
2.31.1