public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/proftpd] f43: Backport a fix from glibc glob(3) for handling unbalanced brace expansions
@ 2026-11-19 18:56 Paul Howarth
0 siblings, 0 replies; only message in thread
From: Paul Howarth @ 2026-11-19 18:56 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/proftpd
Branch : f43
Commit : ab080a411ec66c116d5a7287192d4b30ce7201aa
Author : Paul Howarth <paul@city-fan.org>
Date : 2026-11-19T17:23:04+00:00
Stats : +422/-1 in 3 file(s)
URL : https://src.fedoraproject.org/rpms/proftpd/c/ab080a411ec66c116d5a7287192d4b30ce7201aa?branch=f43
Log:
Backport a fix from glibc glob(3) for handling unbalanced brace expansions
https://github.com/proftpd/proftpd/issues/2473
---
diff --git a/549f8174.patch b/549f8174.patch
new file mode 100644
index 0000000..ed7c33e
--- /dev/null
+++ b/549f8174.patch
@@ -0,0 +1,241 @@
+From 549f81741f930acab56dfb4620c7603de05c20f2 Mon Sep 17 00:00:00 2001
+From: TJ Saunders <tj@castaglia.org>
+Date: Wed, 18 Nov 2026 13:28:36 -0800
+Subject: [PATCH] Issue #2473: Backport a fix from glibc `glob(3)` for handling
+ unbalanced brace expansions.
+
+---
+ lib/glibc-glob.c | 97 ++++++++++++++++++++++++------------------------
+ tests/api/fsio.c | 17 +++++++--
+ 2 files changed, 62 insertions(+), 52 deletions(-)
+
+diff --git a/lib/glibc-glob.c b/lib/glibc-glob.c
+index 6f676e2df8..23edf1410a 100644
+--- 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;
++ while (*cp != '\0')
++ if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\')
++ {
++ if (*++cp == '\0')
++ break;
++ ++cp;
++ }
++ else
++ {
++ if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0))
++ break;
+
+- continue;
+- }
+- 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 char *pattern, int flags,
+
+ 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 char *pattern, int flags,
+
+ /* 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 char *pattern, int flags,
+ 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 char *pattern, int flags,
+ 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 char *pattern, int flags,
+ # 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;
+ }
+ }
+
+diff --git a/tests/api/fsio.c b/tests/api/fsio.c
+index 8a4f01c39c..547f793cb4 100644
+--- a/tests/api/fsio.c
++++ b/tests/api/fsio.c
+@@ -3926,28 +3926,35 @@ START_TEST (fs_glob_test) {
+ glob_t pglob;
+ int res;
+
++ mark_point();
+ res = pr_fs_glob(NULL, 0, NULL, NULL);
+ ck_assert_msg(res < 0, "Failed to handle null arguments");
+ ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
+ strerror(errno), errno);
+
++ mark_point();
+ res = pr_fs_glob(NULL, 0, NULL, &pglob);
+ ck_assert_msg(res < 0, "Failed to handle null arguments");
+ ck_assert_msg(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);
+ ck_assert_msg(res == 0, "Failed to glob: glob(3) returned %d: %s", res,
+ strerror(errno));
+ ck_assert_msg(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);
++ ck_assert_msg(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
+
+@@ -4948,6 +4955,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;
+
+@@ -4960,6 +4968,7 @@ START_TEST (fs_is_nfs_test) {
+ ck_assert_msg(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;
+@@ -5461,7 +5470,7 @@ Suite *tests_get_fsio_suite(void) {
+ 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
++#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/58c9a9cb.patch b/58c9a9cb.patch
new file mode 100644
index 0000000..bf93a3c
--- /dev/null
+++ b/58c9a9cb.patch
@@ -0,0 +1,167 @@
+From 58c9a9cb1c3f45c1d31eeb7b833c725184f5ea64 Mon Sep 17 00:00:00 2001
+From: TJ Saunders <tj@castaglia.org>
+Date: Wed, 18 Nov 2026 14:26:37 -0800
+Subject: [PATCH] In light of Issue #2473, I went through other changes to the
+ stock glibc `glob(3)` implementation, looking for anything else that might
+ bite us.
+
+Nothing in particular stood out, but I chose some of the fixes to apply, as a defensive measure.
+---
+ lib/glibc-glob.c | 47 ++++++++++++++++++++++++++---------------------
+ src/fsio.c | 12 ++++++++++++
+ tests/api/fsio.c | 27 +++++++++++++++++++++++++++
+ 3 files changed, 65 insertions(+), 21 deletions(-)
+
+diff --git a/lib/glibc-glob.c b/lib/glibc-glob.c
+index 23edf1410..ddcc40582 100644
+--- a/lib/glibc-glob.c
++++ b/lib/glibc-glob.c
+@@ -430,6 +430,11 @@ glob_limited (unsigned int depth, const char *pattern, int flags,
+ 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 char *pattern, int flags,
+ }
+ }
+
++ 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 char *pattern, int flags,
+ }
+ }
+
+- 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 *pattern, int flags,
+ 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);
+diff --git a/src/fsio.c b/src/fsio.c
+index 2e38253f1..8a0d9bd65 100644
+--- a/src/fsio.c
++++ b/src/fsio.c
+@@ -4949,6 +4949,18 @@ int pr_fs_glob(const char *pattern, int flags,
+ 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;
+diff --git a/tests/api/fsio.c b/tests/api/fsio.c
+index 547f793cb..376798e47 100644
+--- a/tests/api/fsio.c
++++ b/tests/api/fsio.c
+@@ -3925,6 +3925,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);
+@@ -3947,12 +3948,38 @@ 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);
+ ck_assert_msg(res == GLOB_NOMATCH, "Expected GLOB_NOMATCH, got %d", res);
+ 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);
++ ck_assert_msg(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);
++ ck_assert_msg(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);
++ ck_assert_msg(res == 0, "Expected 0, got %d", res);
++ pr_fs_globfree(&pglob);
++
+ mark_point();
+ pr_fs_globfree(NULL);
+ }
diff --git a/proftpd.spec b/proftpd.spec
index d9c0211..0193e71 100644
--- a/proftpd.spec
+++ b/proftpd.spec
@@ -17,7 +17,7 @@
%undefine _strict_symbol_defs_build
#global prever rc4
-%global baserelease 3
+%global baserelease 4
%global mod_procfs_version 0.3
%global mod_proxy_version 0.9.7
%global mod_vroot_version 0.9.12
@@ -48,6 +48,8 @@ Patch3: proftpd-1.3.4rc1-mod_vroot-test.patch
Patch6: https://github.com/proftpd/proftpd/commit/933abc9a.patch
Patch7: proftpd-1.3.9e-gh2095.patch
Patch8: proftpd-1.3.9e-gh2374.patch
+Patch9: https://github.com/proftpd/proftpd/commit/549f8174.patch
+Patch10: https://github.com/proftpd/proftpd/commit/58c9a9cb.patch
BuildRequires: coreutils
BuildRequires: gcc
@@ -245,6 +247,13 @@ mv contrib/README contrib/README.contrib
# https://github.com/proftpd/proftpd/issues/2374
%patch -P8 -p1 -b .gh2374
+# Backport a fix from glibc glob(3) for handling unbalanced brace expansions
+# https://github.com/proftpd/proftpd/issues/2473
+%patch -P9 -p1 -b .gh2473
+
+# Further fixes from glibc glob(3)
+%patch -P10 -p1 -b .glob
+
# Tweak logrotate script for systemd compatibility (#802178)
sed -i -e '/killall/s/test.*/systemctl try-reload-or-restart proftpd.service/' \
contrib/dist/rpm/proftpd.logrotate
@@ -484,6 +493,10 @@ fi
%{_mandir}/man1/ftpwho.1*
%changelog
+* Thu Nov 19 2026 Paul Howarth <paul@city-fan.org> - 1.3.9e-4
+- Backport a fix from glibc glob(3) for handling unbalanced brace expansions,
+ which could have lead to a stack overflow (GH#2473)
+
* Thu Nov 5 2026 Paul Howarth <paul@city-fan.org> - 1.3.9e-3
- 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-19 18:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 18:56 [rpms/proftpd] f43: 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