about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-10-22 10:00:57 +0200
committerTulio Magno Quites Machado Filho <tuliom@linux.ibm.com>2018-04-13 14:30:20 -0300
commit49a0c33ead1b1eea5b414e9e2574a4fd96291203 (patch)
tree88cf4d70268e8350ed7e1e61af6d0570094cb2fa
parentd8b6b33f1d08642961aff14825c1fa6a0276ad49 (diff)
downloadglibc-release/2.22/master.tar.gz
glibc-release/2.22/master.tar.xz
glibc-release/2.22/master.zip
glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332] release/2.22/master
(cherry picked from commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8)
-rw-r--r--ChangeLog6
-rw-r--r--NEWS4
-rw-r--r--posix/glob.c4
3 files changed, 12 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index c17787e785..5aa721d3be 100644
--- 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 d79e8bcaa1..f67abd6af0 100644
--- a/NEWS
+++ b/NEWS
@@ -100,6 +100,10 @@ Version 2.22.1
   from a one-byte overflow during ~ operator processing (either on the stack
   or the heap, depending on the length of the user name).
 
+* CVE-2017-15804: 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.
+
 
 Version 2.22
 
diff --git a/posix/glob.c b/posix/glob.c
index cd28dc52a2..944b77b4dd 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -866,11 +866,11 @@ glob (pattern, flags, errfunc, pglob)
 		  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