From: fweimer@redhat.com (Florian Weimer)
To: libc-stable@sourceware.org
Subject: [2.26 COMMITTED] Avoid use of strlen in getlogin_r (bug 22447).
Date: Mon, 01 Jan 2018 00:00:00 -0000 [thread overview]
Message-ID: <20181022130138.EB8504399457D@oldenburg.str.redhat.com> (raw)
From: Joseph Myers <joseph@codesourcery.com>
Building glibc with current mainline GCC fails, among other reasons,
because of an error for use of strlen on the nonstring ut_user field.
This patch changes the problem code in getlogin_r to use __strnlen
instead. It also needs to set the trailing NUL byte of the result
explicitly, because of the case where ut_user does not have such a
trailing NUL byte (but the result should always have one).
Tested for x86_64. Also tested that, in conjunction with
<https://sourceware.org/ml/libc-alpha/2017-11/msg00797.html>, it fixes
the build for arm with mainline GCC.
[BZ #22447]
* sysdeps/unix/getlogin_r.c (__getlogin_r): Use __strnlen not
strlen to compute length of ut_user and set trailing NUL byte of
result explicitly.
(cherry picked from commit 4bae615022cb5a5da79ccda83cc6c9ba9f2d479c)
2017-11-22 Joseph Myers <joseph@codesourcery.com>
[BZ #22447]
* sysdeps/unix/getlogin_r.c (__getlogin_r): Use __strnlen not
strlen to compute length of ut_user and set trailing NUL byte of
result explicitly.
diff --git a/NEWS b/NEWS
index 33bc5196c8..5569e8d8d2 100644
--- a/NEWS
+++ b/NEWS
@@ -127,6 +127,7 @@ The following bugs are resolved with this release:
[22375] malloc returns pointer from tcache instead of NULL (CVE-2017-17426)
[22377] Provide a C++ version of iseqsig
[22442] if_nametoindex: Check length of ifname before copying it
+ [22447] Avoid use of strlen in getlogin_r
[22627] $ORIGIN in $LD_LIBRARY_PATH is substituted twice
[22636] PTHREAD_STACK_MIN is too small on x86-64
[22637] nptl: Fix stack guard size accounting
diff --git a/sysdeps/unix/getlogin_r.c b/sysdeps/unix/getlogin_r.c
index 4a6a40eeb2..ad8e9111f6 100644
--- a/sysdeps/unix/getlogin_r.c
+++ b/sysdeps/unix/getlogin_r.c
@@ -80,7 +80,7 @@ __getlogin_r (char *name, size_t name_len)
if (result == 0)
{
- size_t needed = strlen (ut->ut_user) + 1;
+ size_t needed = __strnlen (ut->ut_user, UT_NAMESIZE) + 1;
if (needed > name_len)
{
@@ -89,7 +89,8 @@ __getlogin_r (char *name, size_t name_len)
}
else
{
- memcpy (name, ut->ut_user, needed);
+ memcpy (name, ut->ut_user, needed - 1);
+ name[needed - 1] = 0;
result = 0;
}
}
reply other threads:[~2018-10-22 13:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20181022130138.EB8504399457D@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-stable@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).