public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/proftpd] epel8: Backport a fix from glibc glob(3) for handling unbalanced brace expansions
@ 2026-11-20 15:10 Paul Howarth
  0 siblings, 0 replies; only message in thread
From: Paul Howarth @ 2026-11-20 15:10 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/proftpd
            Branch : epel8
            Commit : 87d22ad200cbb44e94697a03eeb1e45d08e8089a
            Author : Paul Howarth <paul@city-fan.org>
            Date   : 2026-11-20T10:01:14+00:00
            Stats  : +389/-1 in 3 file(s)
            URL    : https://src.fedoraproject.org/rpms/proftpd/c/87d22ad200cbb44e94697a03eeb1e45d08e8089a?branch=epel8

            Log:
            Backport a fix from glibc glob(3) for handling unbalanced brace expansions

https://github.com/proftpd/proftpd/issues/2473

---
diff --git a/proftpd-1.3.6e-gh2473.patch b/proftpd-1.3.6e-gh2473.patch
new file mode 100644
index 0000000..3c14669
--- /dev/null
+++ b/proftpd-1.3.6e-gh2473.patch
@@ -0,0 +1,227 @@
+--- a/lib/glibc-glob.c
++++ b/lib/glibc-glob.c
+@@ -354,12 +354,8 @@ extern int getlogin_r __P ((char *, size_t));
+ #else
+ extern char *getlogin __P ((void));
+ #endif
+-\f
+-static
+-#if __GNUC__ - 0 >= 2
+-inline
+-#endif
+-const char *next_brace_sub __P ((const char *begin));
++
++static const char *next_brace_sub __P ((const char *begin, int flags));
+ 
+ #endif /* GLOB_ONLY_P */
+ 
+@@ -380,48 +376,29 @@ static int __glob_pattern_p (const char *pattern, int quote);
+ static int prefix_array __P ((const char *prefix, char **array, size_t n));
+ static int collated_compare __P ((const __ptr_t, const __ptr_t));
+ 
+-/* Find the end of the sub-pattern in a brace expression.  We define
+-   this as an inline function if the compiler permits.  */
+-static
+-#if __GNUC__ - 0 >= 2
+-inline
+-#endif
+-const char *
+-next_brace_sub (const char *begin)
++/* Find the end of the sub-pattern in a brace expression.  */
++static const char *
++next_brace_sub (const char *cp, int flags)
+ {
+   unsigned int depth = 0;
+-  const char *cp = begin;
+-
+-  while (1)
+-    {
+-      if (depth == 0)
+-	{
+-	  if (*cp != ',' && *cp != '}' && *cp != '\0')
+-	    {
+-	      if (*cp == '{')
+-		++depth;
+-	      ++cp;
+-	      continue;
+-	    }
+-	}
+-      else
+-	{
+-	  while (*cp != '\0' && (*cp != '}' || depth > 0))
+-	    {
+-	      if (*cp == '}')
+-		--depth;
+-	      ++cp;
+-	    }
+-	  if (*cp == '\0')
+-	    /* An incorrectly terminated brace expression.  */
+-	    return NULL;
+ 
+-	  continue;
+-	}
+-      break;
+-    }
++  while (*cp != '\0')
++    if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\')
++      {
++	if (*++cp == '\0')
++	  break;
++	++cp;
++      }
++    else
++      {
++	if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0))
++	  break;
++
++	if (*cp++ == '{')
++	  depth++;
++      }
+ 
+-  return cp;
++  return *cp != '\0' ? cp : NULL;
+ }
+ 
+ #endif /* !GLOB_ONLY_P */
+@@ -460,7 +437,30 @@ glob_limited (unsigned int depth, const
+ 
+   if (flags & GLOB_BRACE)
+     {
+-      const char *begin = strchr (pattern, '{');
++      const char *begin;
++
++      if (flags & GLOB_NOESCAPE)
++        begin = strchr (pattern, '{');
++      else
++        {
++          begin = pattern;
++          while (1)
++            {
++              if (*begin == '\0')
++                {
++                  begin = NULL;
++                  break;
++                }
++
++              if (*begin == '\\' && begin[1] != '\0')
++                ++begin;
++              else if (*begin == '{')
++                break;
++
++              ++begin;
++            }
++        }
++
+       if (begin != NULL)
+ 	{
+ 	  /* Allocate working buffer large enough for our work.  Note that
+@@ -493,7 +493,7 @@ glob_limited (unsigned int depth, const
+ 
+ 	  /* Find the first sub-pattern and at the same time find the
+ 	     rest after the closing brace.  */
+-	  next = next_brace_sub (begin + 1);
++	  next = next_brace_sub (begin + 1, flags);
+ 	  if (next == NULL)
+ 	    {
+ 	      /* It is an illegal expression.  */
+@@ -507,7 +507,7 @@ glob_limited (unsigned int depth, const
+ 	  rest = next;
+ 	  while (*rest != '}')
+ 	    {
+-	      rest = next_brace_sub (rest + 1);
++	      rest = next_brace_sub (rest + 1, flags);
+ 	      if (rest == NULL)
+ 		{
+ 		  /* It is an illegal expression.  */
+@@ -569,7 +569,7 @@ glob_limited (unsigned int depth, const
+ 		break;
+ 
+ 	      p = next + 1;
+-	      next = next_brace_sub (p);
++	      next = next_brace_sub (p, flags);
+ 	      assert (next != NULL);
+ 	    }
+ 
+@@ -797,7 +797,7 @@ glob_limited (unsigned int depth, const
+ # if !defined _AMIGA && !defined WINDOWS32
+       else
+ 	{
+-	  char *end_name = strchr (dirname, '/');
++	  char *end_name = (char *) strchr (dirname, '/');
+ 	  const char *user_name;
+ 	  const char *home_dir;
+ 
+@@ -1174,6 +1174,7 @@ globfree (register glob_t *pglob)
+ 	if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
+ 	  free ((__ptr_t) pglob->gl_pathv[pglob->gl_offs + i]);
+       free ((__ptr_t) pglob->gl_pathv);
++      pglob->gl_pathv = NULL;
+     }
+ }
+ 
+--- a/tests/api/fsio.c
++++ b/tests/api/fsio.c
+@@ -3285,27 +3285,34 @@ START_TEST (fs_glob_test) {
+   glob_t pglob;
+   int res;
+ 
++  mark_point();
+   res = pr_fs_glob(NULL, 0, NULL, NULL);
+   fail_unless(res < 0, "Failed to handle null arguments");
+   fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
+     strerror(errno), errno);
+ 
++  mark_point();
+   res = pr_fs_glob(NULL, 0, NULL, &pglob);
+   fail_unless(res < 0, "Failed to handle null arguments");
+   fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
+     strerror(errno), errno);
+ 
++  mark_point();
+   memset(&pglob, 0, sizeof(pglob));
+   res = pr_fs_glob("?", 0, NULL, &pglob);
+   fail_unless(res == 0, "Failed to glob: %s", strerror(errno));
+   fail_unless(pglob.gl_pathc > 0, "Expected >0, got %lu",
+     (unsigned long) pglob.gl_pathc);
++  pr_fs_globfree(&pglob);
++
++  mark_point();
++  memset(&pglob, 0, sizeof(pglob));
++  res = pr_fs_glob("{a,", GLOB_NOSORT|GLOB_BRACE, NULL, &pglob);
++  fail_unless(res == GLOB_NOMATCH, "Expected GLOB_NOMATCH, got %d", res);
++  pr_fs_globfree(&pglob);
+ 
+   mark_point();
+   pr_fs_globfree(NULL);
+-  if (res == 0) {
+-    pr_fs_globfree(&pglob);
+-  }
+ }
+ END_TEST
+ 
+@@ -4242,6 +4249,7 @@ START_TEST (fs_have_access_test) {
+ }
+ END_TEST
+ 
++#if defined(HAVE_STATFS_F_TYPE) || defined(HAVE_STATFS_F_FSTYPENAME)
+ START_TEST (fs_is_nfs_test) {
+   int res;
+ 
+@@ -4254,6 +4262,7 @@ START_TEST (fs_is_nfs_test) {
+   fail_unless(res == FALSE, "Expected FALSE, got %d", res);
+ }
+ END_TEST
++#endif /* HAVE_STATFS_F_TYPE or HAVE_STATFS_F_FSTYPENAME */
+ 
+ START_TEST (fs_valid_path_test) {
+   int res;
+@@ -4664,7 +4673,9 @@ Suite *tests_get_fsio_suite(void) {
+   tcase_add_test(testcase, fs_fgetsize_test);
+   tcase_add_test(testcase, fs_fadvise_test);
+   tcase_add_test(testcase, fs_have_access_test);
++#if defined(HAVE_STATFS_F_TYPE) || defined(HAVE_STATFS_F_FSTYPENAME)
+   tcase_add_test(testcase, fs_is_nfs_test);
++#endif /* HAVE_STATFS_F_TYPE or HAVE_STATFS_F_FSTYPENAME */
+   tcase_add_test(testcase, fs_valid_path_test);
+   tcase_add_test(testcase, fsio_smkdir_test);
+   tcase_add_test(testcase, fsio_getpipebuf_test);

diff --git a/proftpd-1.3.6e-glob.patch b/proftpd-1.3.6e-glob.patch
new file mode 100644
index 0000000..54070a9
--- /dev/null
+++ b/proftpd-1.3.6e-glob.patch
@@ -0,0 +1,148 @@
+--- a/lib/glibc-glob.c
++++ b/lib/glibc-glob.c
+@@ -430,6 +430,11 @@ glob_limited (unsigned int depth, const
+       return -1;
+     }
+ 
++  /* POSIX requires all slashes to be matched.  This means that with
++     a trailing slash we must match only directories.  */
++  if (pattern[0] && pattern[strlen (pattern) - 1] == '/')
++    flags |= GLOB_ONLYDIR;
++
+   if (!(flags & GLOB_DOOFFS))
+     /* Have to do this so `globfree' knows where to start freeing.  It
+        also makes all the code that uses gl_offs simpler. */
+@@ -585,6 +590,26 @@ glob_limited (unsigned int depth, const
+ 	}
+     }
+ 
++  if (!(flags & GLOB_APPEND))
++    {
++      pglob->gl_pathc = 0;
++      if (!(flags & GLOB_DOOFFS))
++        pglob->gl_pathv = NULL;
++      else
++	{
++	  size_t i;
++	  pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
++					      * sizeof (char *));
++	  if (pglob->gl_pathv == NULL)
++	    return GLOB_NOSPACE;
++
++	  for (i = 0; i <= pglob->gl_offs; ++i)
++	    pglob->gl_pathv[i] = NULL;
++	}
++    }
++
++  oldcount = pglob->gl_pathc + pglob->gl_offs;
++
+   /* Find the filename.  */
+   filename = strrchr (pattern, '/');
+ #if defined __MSDOS__ || defined WINDOWS32
+@@ -681,26 +706,6 @@ glob_limited (unsigned int depth, const
+ 	}
+     }
+ 
+-  if (!(flags & GLOB_APPEND))
+-    {
+-      pglob->gl_pathc = 0;
+-      if (!(flags & GLOB_DOOFFS))
+-        pglob->gl_pathv = NULL;
+-      else
+-	{
+-	  size_t i;
+-	  pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
+-					      * sizeof (char *));
+-	  if (pglob->gl_pathv == NULL)
+-	    return GLOB_NOSPACE;
+-
+-	  for (i = 0; i <= pglob->gl_offs; ++i)
+-	    pglob->gl_pathv[i] = NULL;
+-	}
+-    }
+-
+-  oldcount = pglob->gl_pathc + pglob->gl_offs;
+-
+ #ifndef VMS
+   if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~')
+     {
+@@ -808,7 +813,7 @@ glob_limited (unsigned int depth, const
+ 	      char *newp;
+ 	      newp = (char *) __alloca (end_name - dirname);
+ # ifdef HAVE_MEMPCPY
+-	      *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
++	      *((char *) mempcpy (newp, dirname + 1, end_name - dirname - 1))
+ 		= '\0';
+ # else
+ 	      memcpy (newp, dirname + 1, end_name - dirname);
+--- a/src/fsio.c
++++ b/src/fsio.c
+@@ -4686,6 +4686,18 @@ int pr_fs_glob(const char *pattern, int
+     return -1;
+   }
+ 
++  /* The GLOB_TILDE flag has encountered many issues over the years.
++   * None of the core code uses this flag, so let's preemptively prevent its
++   * usage altogether.
++   */
++  if (flags & GLOB_TILDE) {
++    flags &= ~GLOB_TILDE;
++  }
++
++  if (flags & GLOB_TILDE_CHECK) {
++    flags &= ~GLOB_TILDE_CHECK;
++  }
++
+   flags |= GLOB_ALTDIRFUNC;
+ 
+   pglob->gl_closedir = (void (*)(void *)) pr_fsio_closedir;
+--- a/tests/api/fsio.c
++++ b/tests/api/fsio.c
+@@ -3284,6 +3284,7 @@ END_TEST
+ START_TEST (fs_glob_test) {
+   glob_t pglob;
+   int res;
++  char buf[16382];
+ 
+   mark_point();
+   res = pr_fs_glob(NULL, 0, NULL, NULL);
+@@ -3305,6 +3306,7 @@ START_TEST (fs_glob_test) {
+     (unsigned long) pglob.gl_pathc);
+   pr_fs_globfree(&pglob);
+ 
++  /* See Issue #2473. */
+   mark_point();
+   memset(&pglob, 0, sizeof(pglob));
+   res = pr_fs_glob("{a,", GLOB_NOSORT|GLOB_BRACE, NULL, &pglob);
+@@ -3312,6 +3314,31 @@ START_TEST (fs_glob_test) {
+   pr_fs_globfree(&pglob);
+ 
+   mark_point();
++  memset(buf, '/', sizeof(buf)-1);
++  buf[sizeof(buf)-1] = '\0';
++  memset(&pglob, 0, sizeof(pglob));
++  res = pr_fs_glob(buf, 0, NULL, &pglob);
++  fail_unless(res == GLOB_NOSPACE, "Expected GLOB_NOSPACE, got %d", res);
++  pr_fs_globfree(&pglob);
++
++  mark_point();
++  memset(buf, '/', sizeof(buf)-1);
++  buf[1] = '*';
++  buf[sizeof(buf)-3] = 's';
++  buf[sizeof(buf)-2] = 'h';
++  buf[sizeof(buf)-1] = '\0';
++  memset(&pglob, 0, sizeof(pglob));
++  res = pr_fs_glob(buf, 0, NULL, &pglob);
++  fail_unless(res == GLOB_NOSPACE, "Expected GLOB_NOSPACE, got %d", res);
++  pr_fs_globfree(&pglob);
++
++  mark_point();
++  memset(&pglob, 0, sizeof(pglob));
++  res = pr_fs_glob("", 0, NULL, &pglob);
++  fail_unless(res == 0, "Expected 0, got %d", res);
++  pr_fs_globfree(&pglob);
++
++  mark_point();
+   pr_fs_globfree(NULL);
+ }
+ END_TEST

diff --git a/proftpd.spec b/proftpd.spec
index ef7fdf5..0e80786 100644
--- a/proftpd.spec
+++ b/proftpd.spec
@@ -66,7 +66,7 @@
 %undefine _strict_symbol_defs_build
 
 #global prever rc3
-%global baserelease 12
+%global baserelease 13
 %global mod_procfs_version 0.2
 %global mod_vroot_version 0.9.5
 
@@ -116,6 +116,8 @@ Patch125:		proftpd-1.3.6e-gh2095.patch
 Patch126:		proftpd-1.3.6e-gh2374.patch
 Patch127:		proftpd-1.3.6e-CVE-2026-119146.patch
 Patch128:		proftpd-1.3.6e-CVE-2026-119147.patch
+Patch129:		proftpd-1.3.6e-gh2473.patch
+Patch130:		proftpd-1.3.6e-glob.patch
 
 BuildRequires:		coreutils
 BuildRequires:		gcc
@@ -427,6 +429,13 @@ sed -i -e '/^[[:space:]]*TLSCipherSuite[[:space:]]*PROFILE=SYSTEM$/d' mod_tls.co
 # https://github.com/proftpd/proftpd/commit/b7d3de4565ae448a510feecd17b41923e44bfe16
 %patch -P 128 -p1 -b .cve-2026-119147
 
+# Backport a fix from glibc glob(3) for handling unbalanced brace expansions
+# https://github.com/proftpd/proftpd/issues/2473
+%patch -P129 -p1 -b .gh2473
+
+# Further fixes from glibc glob(3)
+%patch -P130 -p1 -b .glob
+
 %if %{use_systemd}
 # Tweak logrotate script for systemd compatibility (#802178)
 sed -i -e '/killall/s/test.*/systemctl reload proftpd.service/' \
@@ -710,6 +719,10 @@ fi
 %{_mandir}/man1/ftpwho.1*
 
 %changelog
+* Thu Nov 19 2026 Paul Howarth <paul@city-fan.org> - 1.3.6e-13
+- Backport a fix from glibc glob(3) for handling unbalanced brace expansions,
+  which could have lead to a stack overflow (GH#2473)
+
 * Wed Nov 11 2026 Paul Howarth <paul@city-fan.org> - 1.3.6e-12
 - Fix some issues in mod_copy (not enabled by default)
   - <Limit READ> configurations were not honored by SITE COPY as they should be

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 15:10 [rpms/proftpd] epel8: Backport a fix from glibc glob(3) for handling unbalanced brace expansions Paul Howarth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox