[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Fwd: kdelibs/kdecore/netwm.cpp patch
From: Stephan Kulow <coolo () kde ! org>
Date: 2001-07-06 15:26:51
[Download RAW message or body]
---------- Forwarded Message ----------
Subject: kdelibs/kdecore/netwm.cpp patch
Date: Fri, 6 Jul 2001 11:53:37 +0300
From: Ilya Konstantinov <future@shiny.co.il>
To: Stephan Kulow <coolo@kde.org>
Hi Stephan,
While developing _NET_WM_NAME support for Mozilla (to allow Mozilla to
display UTF-8 window captions when running on X11 / kwin) I stumbled
upon some bugs in netwm.cpp:
- UTF8_STRING are terminated with NULL while they shouldn't be
according to the UTF8_STRING standard.
- nstrndup doesn't allocate one more byte and fill it with NULL, and
that causes some binary garbage, since properties are copied to N
(where N is the property length) - and since I don't include the NULL
in the property (as the standard says), the nstrndup produces an
unterminated dest string.
- properties received from XGetWindowProperty don't require
null-terminating on our own, since XGetWindowProperty already
promises them alloced with nitems_return+1 bytes and null-terminated.
Here's a patch to fix those issues. I really hope we'll get it in
before KDE 2.2 release.
(I noticed this is Trolltech's code, so if there are licensing
questions, the patch is thereby released into Public Domain :)
-------------------------------------------------------
--
People in cars cause accidents. Accidents in cars cause people.
["Anhang: 1" (text/plain)]
Index: netwm.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/netwm.cpp,v
retrieving revision 1.48
diff -u -r1.48 netwm.cpp
--- netwm.cpp 2001/05/25 11:39:20 1.48
+++ netwm.cpp 2001/07/04 21:05:31
@@ -118,8 +118,9 @@
static char *nstrndup(const char *s1, int l) {
if (! s1 || l == 0) return (char *) 0;
- char *s2 = new char[l];
+ char *s2 = new char[l+1];
strncpy(s2, s1, l);
+ s2[l] = '\0';
return s2;
}
@@ -951,7 +952,7 @@
(unsigned char *) &(p->supportwindow), 1);
XChangeProperty(p->display, p->supportwindow, net_wm_name, UTF8_STRING, 8,
PropModeReplace, (unsigned char *) p->name,
- strlen(p->name) + 1);
+ strlen(p->name));
}
@@ -1517,9 +1518,6 @@
&format_ret, &nitems_ret, &unused, &data_ret)
== Success) {
if (type_ret == UTF8_STRING && format_ret == 8) {
- // force the last element in the data array to be NUL
- data_ret[nitems_ret - 1] = '\0';
-
const char *d = (const char *) data_ret;
unsigned int s, n, index;
@@ -1601,7 +1599,7 @@
&nitems_ret, &unused, &name_ret)
== Success) {
if (type_ret == UTF8_STRING && format_ret == 8)
- p->name = nstrdup((const char *) name_ret);
+ p->name = nstrndup((const char *) name_ret, nitems_ret);
if ( name_ret )
XFree(name_ret);
@@ -2111,7 +2109,7 @@
p->name = nstrdup(name);
XChangeProperty(p->display, p->window, net_wm_name, UTF8_STRING, 8,
PropModeReplace, (unsigned char *) p->name,
- strlen(p->name) + 1);
+ strlen(p->name));
}
@@ -2122,7 +2120,7 @@
p->visible_name = nstrdup(visibleName);
XChangeProperty(p->display, p->window, net_wm_visible_name, UTF8_STRING, 8,
PropModeReplace, (unsigned char *) p->visible_name,
- strlen(p->visible_name) + 1);
+ strlen(p->visible_name));
}
@@ -2133,7 +2131,7 @@
p->icon_name = nstrdup(iconName);
XChangeProperty(p->display, p->window, net_wm_icon_name, UTF8_STRING, 8,
PropModeReplace, (unsigned char *) p->icon_name,
- strlen(p->icon_name) + 1);
+ strlen(p->icon_name));
}
@@ -2144,7 +2142,7 @@
p->visible_icon_name = nstrdup(visibleIconName);
XChangeProperty(p->display, p->window, net_wm_visible_icon_name, UTF8_STRING, 8,
PropModeReplace, (unsigned char *) p->visible_icon_name,
- strlen(p->visible_icon_name) + 1);
+ strlen(p->visible_icon_name));
}
@@ -2570,8 +2568,7 @@
(long) BUFSIZE, False, UTF8_STRING, &type_ret,
&format_ret, &nitems_ret, &unused, &data_ret)
== Success) {
- if (type_ret == UTF8_STRING && format_ret == 8 &&
- nitems_ret > 0) {
+ if (type_ret == UTF8_STRING && format_ret == 8 && nitems_ret > 0) {
if (p->visible_name) delete [] p->visible_name;
p->visible_name = nstrndup((const char *) data_ret, nitems_ret);
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic