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

From: Dimitris Papastamos <sin_AT_2f30.org>
Date: Mon, 1 Dec 2014 20:19:21 +0000

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.
Received on Mon Dec 01 2014 - 21:19:21 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 01 2014 - 21:24:08 CET