00db10
commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8
00db10
Author: Paul Eggert <eggert@cs.ucla.edu>
00db10
Date:   Sun Oct 22 10:00:57 2017 +0200
00db10
00db10
    glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]
00db10
00db10
CVE-2017-15804 was assigned to this issue after commit.
00db10
00db10
diff --git a/posix/glob.c b/posix/glob.c
00db10
index 15cf3d5cccab0ee0..e09314712d68c1b8 100644
00db10
--- a/posix/glob.c
00db10
+++ b/posix/glob.c
00db10
@@ -806,11 +806,11 @@ glob (pattern, flags, errfunc, pglob)
00db10
 		  char *p = mempcpy (newp, dirname + 1,
00db10
 				     unescape - dirname - 1);
00db10
 		  char *q = unescape;
00db10
-		  while (*q != '\0')
00db10
+		  while (q != end_name)
00db10
 		    {
00db10
 		      if (*q == '\\')
00db10
 			{
00db10
-			  if (q[1] == '\0')
00db10
+			  if (q + 1 == end_name)
00db10
 			    {
00db10
 			      /* "~fo\\o\\" unescape to user_name "foo\\",
00db10
 				 but "~fo\\o\\/" unescape to user_name