For whatever reason, mem2strcpy places the nul-terminator at the end of the buffer instead of at the end of the string it copies. This makes it completely useless for our purposes, since one would have to add a terminator manually to avoid getting garbage. Just use memcpy instead. Fixes: ff5dc96eb ("unshare: Add options to map blocks of user/group IDs") Signed-off-by: Sean Anderson <seanga2@xxxxxxxxx> Reported-by: Daniel Gerber <dg@xxxxxxxxx> --- sys-utils/unshare.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 443358952..889c561ca 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -387,8 +387,9 @@ static int uint_to_id(const char *name, size_t sz) { char buf[UID_BUFSIZ]; - mem2strcpy(buf, name, sz, sizeof(buf)); - return strtoul_or_err(name, _("could not parse ID")); + memcpy(buf, name, min(sz, sizeof(buf) - 1)); + buf[sz] = '\0'; + return strtoul_or_err(buf, _("could not parse ID")); } /** -- 2.34.1