Re: [dwm] testing URL

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Thu, 10 May 2007 13:49:45 +0200

On Wed, May 09, 2007 at 06:14:08PM +0000, David Tweed wrote:
> Thanks to both the testers.
> I'm currently a bit stuck figuring out what
> is going wrong. One thing I have noticed is that there are 5 uses of
> strncpy in dwm-4.0, only one forcibly writes a zero byte to the end of
> the copied-to array just in case (the
> "strncpy(stext, strerror(errno), sizeof stext - 1);" in main.c).
> (For the uninitiated, strncpy has bizarre behaviour,
> it won't write more than the specified number of bytes but if
> there are more it won't zero-terminate and you can't find out
> whether that happened.) I was wondering if somehow the URL

Hmm, but in main.c the stext buffer is zero-terminated
explicitely a line later, however, this is not done in
updatetitle().

I pushed the following patch to updatetitle():

diff -r c7b4661e8902 client.c
--- a/client.c Wed May 09 11:31:14 2007 +0200
+++ b/client.c Thu May 10 13:47:02 2007 +0200
@@ -365,16 +365,18 @@ updatetitle(Client *c) {
                 XGetWMName(dpy, c->win, &name);
         if(!name.nitems)
                 return;
- if(name.encoding == XA_STRING)
- strncpy(c->name, (char *)name.value, sizeof c->name);
+ if(name.encoding == XA_STRING) {
+ strncpy(c->name, (char *)name.value, sizeof c->name - 1);
+ }
         else {
                 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
                 && n > 0 && *list)
                 {
- strncpy(c->name, *list, sizeof c->name);
+ strncpy(c->name, *list, sizeof c->name - 1);
                         XFreeStringList(list);
                 }
         }
+ c->name[sizeof c->name - 1] = '\0';
         XFree(name.value);
 }
 
Please let me know if hg tip works for you.

> is giving an unterminated string, but it doesn't seem to be.
> And it's only happening for me. :-(

Do you have a backtrace? Maybe it's an Xlib-bug, maybe very
special to a specific font(set)?

Regards,

-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
Received on Thu May 10 2007 - 13:49:45 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:41:12 UTC