util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: util-linux@vger.kernel.org, Karel Zak <kzak@redhat.com>
Cc: Daniel Gerber <dg@atufi.org>, Sean Anderson <seanga2@gmail.com>
Subject: [PATCH 1/2] unshare: Fix parsing of id maps
Date: Sat, 15 Jan 2022 11:29:25 -0500	[thread overview]
Message-ID: <20220115162926.546843-2-seanga2@gmail.com> (raw)
In-Reply-To: <20220115162926.546843-1-seanga2@gmail.com>

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@gmail.com>
Reported-by: Daniel Gerber <dg@atufi.org>
---

 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


  reply	other threads:[~2022-01-15 16:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-15 16:29 [PATCH 0/2] unshare: some idmap fixes Sean Anderson
2022-01-15 16:29 ` Sean Anderson [this message]
2022-01-17  8:50   ` [PATCH 1/2] unshare: Fix parsing of id maps Karel Zak
2022-01-15 16:29 ` [PATCH 2/2] unshare: Fix doc comments Sean Anderson
2022-01-18 11:35 ` [PATCH 0/2] unshare: some idmap fixes Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220115162926.546843-2-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=dg@atufi.org \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).