Based on:

From a159b53fa059947cc2548e3b0d5bdcf7b9630ba8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 22 Oct 2017 10:00:57 +0200
Subject: [PATCH] glob: Fix buffer overflow during GLOB_TILDE unescaping 

diff -Naur a/posix/glob.c b/posix/glob.c
--- a/posix/glob.c	2017-12-20 15:32:59.037906342 +0530
+++ b/posix/glob.c	2017-12-20 15:34:32.957904298 +0530
@@ -677,11 +677,11 @@
 		  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

