]> 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>
Sat, 2 Dec 2017 21:58:11 +0000 (22:58 +0100)
(cherry picked from commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8)

ChangeLog
NEWS
posix/glob.c

index 01a1e99d8359bd60544749aa6fa3eda20d774fbb..77eea1e0246c956ab6bcfbda7b7ed51af7de142d 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-21  Florian Weimer  <fweimer@redhat.com>
 
        * posix/Makefile (tests): Add tst-glob-tilde.
diff --git a/NEWS b/NEWS
index a70d21eb40cdd255b9a741184b4b6ce1a5c9536f..0531dfa9c6dc05519825a251c08c77308564961a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,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:
 
   [20790] Fix rpcgen buffer overrun
index 026bc063d3a046be5f9c8636ba1fcfe59dcc423b..f3fa8077004bbc2f13cbbcd7f8224fb4fab89419 100644 (file)
@@ -863,11 +863,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