Skip to content

Commit 7f42e16

Browse files
committed
Cache window name length when checking for truncated string
Don't calculate it 3 times on the same data. This also makes lines a bit shorter. Related to QubesOS/qubes-issues#5986
1 parent 82634df commit 7f42e16

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

gui-daemon/xside.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,16 +3063,18 @@ static void handle_wmname(Ghandles * g, struct windowdata *vm_window)
30633063
XTextProperty text_prop;
30643064
struct msg_wmname untrusted_msg;
30653065
char buf[sizeof(untrusted_msg.data) + sizeof(g->vmname) + 3];
3066+
size_t name_len;
30663067
char *list[1] = { buf };
30673068

30683069
read_struct(g->vchan, untrusted_msg);
30693070
/* sanitize start */
30703071
untrusted_msg.data[sizeof(untrusted_msg.data) - 1] = 0;
30713072
// If the agent has changed the end of very long title to U+2026 but utf8 is disabled
3073+
name_len = strlen(untrusted_msg.data);
30723074
if (!g->allow_utf8_titles
3073-
&& strlen(untrusted_msg.data) > 3
3074-
&& strcmp(untrusted_msg.data + strlen(untrusted_msg.data) - 3, "\xE2\x80\xA6") == 0) {
3075-
strcpy(untrusted_msg.data + strlen(untrusted_msg.data) - 3, "...");
3075+
&& name_len > 3
3076+
&& strcmp(untrusted_msg.data + name_len - 3, "\xE2\x80\xA6") == 0) {
3077+
strcpy(untrusted_msg.data + name_len - 3, "...");
30763078
}
30773079
sanitize_string_from_vm((unsigned char *) (untrusted_msg.data),
30783080
g->allow_utf8_titles);

0 commit comments

Comments
 (0)