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