]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 22 Oct 2017 08:00:57 +0000 (10:00 +0200)
committerAurelien Jarno <aurelien@aurel32.net>
Fri, 1 Dec 2017 20:51:27 +0000 (21:51 +0100)
(cherry picked from commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8)

ChangeLog
NEWS
posix/glob.c

index 179381679487e0260d7a9c9ef9d9b2fe351dcbc4..0ab08782b4c6973950f8a1052d5873d751e6811f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-22  Paul Eggert <eggert@cs.ucla.edu>
+
+       [BZ #22332]
+       * posix/glob.c (__glob): Fix buffer overflow during GLOB_TILDE
+       unescaping.
+
 2017-10-23  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * malloc/malloc.c (_int_malloc): Add SINGLE_THREAD_P path.
diff --git a/NEWS b/NEWS
index 037b28cb9bb6b5506a4b277851a13c0d7fa2294b..7d3a326d88ee9aced97689b7ec07940e4df91c93 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,10 @@ Security related changes:
   processing, leading to a memory leak and, potentially, to a denial
   of service.
 
+  The glob function, when invoked with GLOB_TILDE and without
+  GLOB_NOESCAPE, could write past the end of a buffer while
+  unescaping user names.  Reported by Tim Rühsen.
+
 The following bugs are resolved with this release:
 
   [16750] ldd: Never run file directly.
index c761c0861ddb49eab67a173938c2f541d6836673..b2273ea7bce40552f3d45d74214868dec8cf232d 100644 (file)
@@ -850,11 +850,11 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
                  char *p = mempcpy (newp, dirname + 1,
                                     unescape - dirname - 1);
                  char *q = unescape;
-                 while (*q != '\0')
+                 while (q != end_name)
                    {
                      if (*q == '\\')
                        {
-                         if (q[1] == '\0')
+                         if (q + 1 == end_name)
                            {
                              /* "~fo\\o\\" unescape to user_name "foo\\",
                                 but "~fo\\o\\/" unescape to user_name