Re: [dev] [PATCH] [lsw] Ensure buf[] is always null-terminated after strncpy()

From: Anselm R Garbe <garbeam_AT_gmail.com>
Date: Mon, 22 Dec 2014 11:38:10 +0100

On 1 December 2014 at 21:19, Dimitris Papastamos <sin_AT_2f30.org> wrote:
> On Mon, Dec 01, 2014 at 08:09:40PM +0000, Dimitris Papastamos wrote:
>> if(!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) {
>> strncpy(buf, list[0], sizeof buf);
>> XFreeStringList(list);
>> - }
>> - else
>> + } else
>> strncpy(buf, (char *)prop.value, sizeof buf);
>> XFree(prop.value);
>> + buf[sizeof buf - 1] = '\0';
>> return buf;
>
> If we do hit this case, it will result in truncation so it may be
> better to strdup() after all. This just patch just avoids a segfault
> basically.

IMO the truncation is ok given the fact that lsw output is not
ultra-critical in terms of full matching for postprocessing input.
Even decorating WMs would truncate. So I applied this suggestion!

Thanks and BR,
Anselm
Received on Mon Dec 22 2014 - 11:38:10 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 22 2014 - 11:48:07 CET