]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/env.c: Replace strncpy(3) call by stpcpy(mempcpy(), "")
authorAlejandro Colomar <alx@kernel.org>
Wed, 15 Nov 2023 21:49:13 +0000 (22:49 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 4 Dec 2023 04:24:29 +0000 (22:24 -0600)
commit72060a2b2bdede62fd5874f10d523379a4dbdcc4
tree47b066a1468ae92bd1874a254d70b5002b226ced
parentdbb37b1b31a2bf89dd2a2bd6f856478b5059174e
lib/env.c: Replace strncpy(3) call by stpcpy(mempcpy(), "")

We were using strncpy(3), which is designed to copy from a string into a
(null-padded) fixed-size character array.  However, we were doing the
opposite: copying from a known-size array (which was a prefix of a
string), into a string.  That's why we had to manually zero the buffer
afterwards.

Use instead mempcpy(3) to copy the non-null bytes, and then terminate
with a null byte with stpcpy(..., "").

Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/env.c