summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-06-07 23:00:06 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-06-08 23:56:25 -0700
commit456b0fafa73f1227adf07ee924b316cbf9fe83cb (patch)
treee1e0bd60b051ebafcf2f3e052f491d48097a8471
parentee3b33c9e757b8d7f9f4c9761f3c66826adc4f59 (diff)
When matching window names, ensure name lengths match too
Prevents strncmp returning on partial matches when one is shorter. https://bugs.freedesktop.org/show_bug.cgi?id=37710 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
-rw-r--r--dsimple.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/dsimple.c b/dsimple.c
index a9b8678..150f9db 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -253,7 +253,8 @@ recursive_Window_With_Name (
xcb_connection_t *dpy,
xcb_window_t window,
struct wininfo_cookies *cookies,
- const char *name)
+ const char *name,
+ size_t namelen)
{
xcb_window_t *children;
unsigned int nchildren;
@@ -273,7 +274,8 @@ recursive_Window_With_Name (
int prop_name_len = xcb_get_property_value_length (prop);
/* can't use strcmp, since prop.name is not null terminated */
- if (strncmp (prop_name, name, prop_name_len) == 0) {
+ if ((namelen == prop_name_len) &&
+ memcmp (prop_name, name, namelen) == 0) {
w = window;
}
}
@@ -294,7 +296,8 @@ recursive_Window_With_Name (
if (xcb_get_wm_name_reply (dpy, cookies->get_wm_name,
&nameprop, &err)) {
/* can't use strcmp, since nameprop.name is not null terminated */
- if (strncmp (nameprop.name, name, nameprop.name_len) == 0) {
+ if ((namelen == nameprop.name_len) &&
+ memcmp (nameprop.name, name, namelen) == 0) {
w = window;
}
@@ -309,7 +312,8 @@ recursive_Window_With_Name (
int prop_name_len = xcb_get_property_value_length (prop);
/* can't use strcmp, since prop.name is not null terminated */
- if (strncmp (prop_name, name, prop_name_len) == 0) {
+ if ((namelen == prop_name_len) &&
+ memcmp (prop_name, name, namelen) == 0) {
w = window;
}
}
@@ -354,7 +358,7 @@ recursive_Window_With_Name (
for (i = 0; i < nchildren; i++) {
w = recursive_Window_With_Name (dpy, children[i],
- &child_cookies[i], name);
+ &child_cookies[i], name, namelen);
if (w)
break;
}
@@ -392,7 +396,7 @@ Window_With_Name (
cookies.get_wm_name = xcb_get_wm_name (dpy, top);
cookies.query_tree = xcb_query_tree (dpy, top);
xcb_flush (dpy);
- return recursive_Window_With_Name(dpy, top, &cookies, name);
+ return recursive_Window_With_Name(dpy, top, &cookies, name, strlen(name));
}