[PATCH] weston-launch: Fixed TTY switching
Bill Spitzak
spitzak at gmail.com
Wed Apr 8 13:11:35 PDT 2015
On 04/07/2015 05:03 PM, Bryce Harrington wrote:
> I'm sure this is not going to ever be a problem since tty filenames and
> paths are on the short side, but since the tty string is an input
> parameter to this routine, it would be better defensive programming to
> use strncpy.
strncpy is not a fix and should never be used.
That is because the proper invocation is:
strncpy(dest, len-1, src); dest[len-1] = 0;
This is almost always done incorrectly, and even when correct it is hard
to read and it wastes time filling the buffer with 0 when only the first
0 needs to be written.
The best solution is to use strlcpy.
If politics make that impossible, use snprintf(dest, len, "%s", src)
which is exactly the same as strlcpy, including the return value!
(imagine that...)
More information about the wayland-devel
mailing list