]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix nscd readlink argument aliasing (bug 22446).
authorJoseph Myers <joseph@codesourcery.com>
Mon, 18 Dec 2017 18:50:40 +0000 (18:50 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 18 Dec 2017 18:50:40 +0000 (18:50 +0000)
Current GCC mainline detects that nscd calls readlink with the same
buffer for both input and output, which is not valid (those arguments
are both restrict-qualified in POSIX).  This patch makes it use a
separate buffer for readlink's input (with a size that is sufficient
to avoid truncation, so there should be no problems with warnings
about possible truncation, though not strictly minimal, but much
smaller than the buffer for output) to avoid this problem.

Tested compilation for aarch64-linux-gnu with build-many-glibcs.py.

[BZ #22446]
* nscd/connections.c (handle_request) [SO_PEERCRED]: Use separate
buffers for readlink input and output.

ChangeLog
nscd/connections.c

index 31b25abb0ac4660d9d49bcdc28389207ddbbf3e3..c5ee8fc91ac6bad9585a65477ceed4fbf6189de2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-18  Joseph Myers  <joseph@codesourcery.com>
+
+       [BZ #22446]
+       * nscd/connections.c (handle_request) [SO_PEERCRED]: Use separate
+       buffers for readlink input and output.
+
 2017-12-18  Sergei Trofimovich  <slyfox@gentoo.org>
 
        [BZ #22624]
index cc1ed72077640a8b45b8d70f3abc13814a0e8faf..dab722dcb2f689b44e73836f508277b36ff034ae 100644 (file)
@@ -1077,14 +1077,15 @@ cannot handle old request version %d; current version is %d"),
       if (debug_level > 0)
        {
 #ifdef SO_PEERCRED
+         char pbuf[sizeof ("/proc//exe") + 3 * sizeof (long int)];
 # ifdef PATH_MAX
          char buf[PATH_MAX];
 # else
          char buf[4096];
 # endif
 
-         snprintf (buf, sizeof (buf), "/proc/%ld/exe", (long int) pid);
-         ssize_t n = readlink (buf, buf, sizeof (buf) - 1);
+         snprintf (pbuf, sizeof (pbuf), "/proc/%ld/exe", (long int) pid);
+         ssize_t n = readlink (pbuf, buf, sizeof (buf) - 1);
 
          if (n <= 0)
            dbg_log (_("\