public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Than Ngo <than@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/patch] f45: - Bugfix update
Date: Tue, 29 Sep 2026 15:40:47 GMT [thread overview]
Message-ID: <179069644712.1.10710172879371239946.rpms-patch-ca4e7786976f@fedoraproject.org> (raw)
A new commit has been pushed.
Repo : rpms/patch
Branch : f45
Commit : ca4e7786976f2987d01f7b03af4623d0a25435aa
Author : Than Ngo <than@redhat.com>
Date : 2026-09-29T17:39:39+02:00
Stats : +470/-1 in 9 file(s)
URL : https://src.fedoraproject.org/rpms/patch/c/ca4e7786976f2987d01f7b03af4623d0a25435aa?branch=f45
Log:
- Bugfix update
* Avoid null pointer derefence with bad hunks
* Don’t infloop on null ranges
---
diff --git a/0001-patch:Add-some-missing-filename-quoting.patch b/0001-patch:Add-some-missing-filename-quoting.patch
new file mode 100644
index 0000000..ce7c378
--- /dev/null
+++ b/0001-patch:Add-some-missing-filename-quoting.patch
@@ -0,0 +1,21 @@
+commit aea66268c956bb001ece14c98fd5542f368a6177
+Author: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
+Date: Sat Apr 5 17:25:45 2025 +0200
+
+ Add some missing filename quoting
+
+ * src/patch.c (main): Quote outname.
+
+diff --git a/src/patch.c b/src/patch.c
+index e4d0524..6c5d926 100644
+--- a/src/patch.c
++++ b/src/patch.c
+@@ -616,7 +616,7 @@ main (int argc, char **argv)
+ struct stat outstat;
+
+ if (stat_file (outname, &outstat) != 0)
+- say ("Cannot stat file %s, skipping backup\n", outname);
++ say ("Cannot stat file %s, skipping backup\n", quotearg (outname));
+ else
+ output_file (&(struct outfile) { .name = outname },
+ &outstat, nullptr, nullptr,
diff --git a/0002-patch:Reject-empty-filenames.patch b/0002-patch:Reject-empty-filenames.patch
new file mode 100644
index 0000000..b4b62ce
--- /dev/null
+++ b/0002-patch:Reject-empty-filenames.patch
@@ -0,0 +1,54 @@
+commit 4c302306a8208817f017113edbee89c8aeb24b01
+Author: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
+Date: Sat Apr 5 17:13:55 2025 +0200
+
+ Reject empty filenames
+
+ * src/safe.c (safe_xstat): Reject empty pathnames.
+ * tests/bad-filenames: Add a new test.
+ * src/patch.c (main): Don't check if the input file is writable when
+ we're not going to modify it.
+
+diff --git a/src/patch.c b/src/patch.c
+index 6c5d926..91cb646 100644
+--- a/src/patch.c
++++ b/src/patch.c
+@@ -323,7 +323,8 @@ main (int argc, char **argv)
+ }
+ }
+
+- if (read_only_behavior != RO_IGNORE
++ if (! skip_rest_of_patch
++ && read_only_behavior != RO_IGNORE
+ && ! inerrno && ! S_ISLNK (instat.st_mode)
+ && safe_access (inname, W_OK) != 0)
+ {
+diff --git a/src/safe.c b/src/safe.c
+index eda9922..065c13b 100644
+--- a/src/safe.c
++++ b/src/safe.c
+@@ -571,6 +571,8 @@ safe_xstat (char *pathname, struct stat *buf, int flags)
+ int dirfd = traverse_path (&pathname, false);
+ if (dirfd == DIRFD_INVALID)
+ return -1;
++ if (! strcmp (pathname, ""))
++ return EINVAL;
+ return fstatat (dirfd, pathname, buf, flags);
+ }
+
+diff --git a/tests/bad-filenames b/tests/bad-filenames
+index b663dad..d9f4930 100644
+--- a/tests/bad-filenames
++++ b/tests/bad-filenames
+@@ -200,3 +200,11 @@ No file to patch. Skipping patch.
+ 1 out of 1 hunk ignored
+ status: 1
+ EOF
++
++# Empty filenames are not allowed:
++
++check 'emit_patch f | patch -r- "" || echo status: $?' <<EOF
++File '' is not a regular file -- refusing to patch
++1 out of 1 hunk ignored
++status: 1
++EOF
diff --git a/0003-patch:Skip-read-only-check-when-output-file-specified.patch b/0003-patch:Skip-read-only-check-when-output-file-specified.patch
new file mode 100644
index 0000000..d83a248
--- /dev/null
+++ b/0003-patch:Skip-read-only-check-when-output-file-specified.patch
@@ -0,0 +1,42 @@
+commit d161c9a9dbd24bb7e0356e4e07983345777d85aa
+Author: Daniel Black <daniel@mariadb.org>
+Date: Thu May 1 14:33:19 2025 +1000
+
+ Skip read-only check when output file specified
+
+ Only check if input files are read-only when overwriting them; skip
+ that check when the output goes to a different file.
+
+ * src/patch.c (main): Set read_only_behavior to RO_IGNORE when an output
+ file has been specified.
+ * tests/read-only-files: Add test case.
+
+diff --git a/src/patch.c b/src/patch.c
+index 91cb646..42c093c 100644
+--- a/src/patch.c
++++ b/src/patch.c
+@@ -204,7 +204,10 @@ main (int argc, char **argv)
+
+ init_output (&outstate);
+ if (outfile)
+- outstate.ofp = open_outfile (outfile);
++ {
++ outstate.ofp = open_outfile (outfile);
++ read_only_behavior = RO_IGNORE;
++ }
+
+ /* Make sure we clean up in case of disaster. */
+ init_signals ();
+diff --git a/tests/read-only-files b/tests/read-only-files
+index b66ddb9..9f6bf7c 100644
+--- a/tests/read-only-files
++++ b/tests/read-only-files
+@@ -67,3 +67,8 @@ check 'patch -f -p0 --read-only=ignore < f.diff || echo "Status: $?"' <<EOF
+ patching file f
+ patching file f
+ EOF
++
++check 'patch -o - f /dev/null || echo "Status: $?"' <<EOF
++patching file - (read from f)
++three
++EOF
diff --git a/0004-patch:Avoid-null-pointer-derefence-with-bad-hunks.patch b/0004-patch:Avoid-null-pointer-derefence-with-bad-hunks.patch
new file mode 100644
index 0000000..321f69e
--- /dev/null
+++ b/0004-patch:Avoid-null-pointer-derefence-with-bad-hunks.patch
@@ -0,0 +1,64 @@
+commit e6d6a4e021660679d7fc9150f981d4920f722313
+Author: Paul Eggert <eggert@cs.ucla.edu>
+Date: Tue Apr 21 10:05:02 2026 -0700
+
+ Avoid null pointer derefence with bad hunks
+
+ Problem reported by Michał Majchrowicz.
+ * src/pch.c (another_hunk): Keep chars_read positive
+ even with malformed hunks.
+
+diff --git a/src/pch.c b/src/pch.c
+index e1319db..b83253c 100644
+--- a/src/pch.c
++++ b/src/pch.c
+@@ -1694,7 +1694,8 @@ another_hunk (enum diff difftype, bool rev)
+ p_end = filldst-1;
+ malformed ();
+ }
+- chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
++ chars_read -= (1 < chars_read && fillsrc == p_ptrn_lines
++ && incomplete_line ());
+ p_Char[fillsrc] = ch;
+ p_line[fillsrc] = s;
+ p_len[fillsrc++] = chars_read;
+@@ -1711,7 +1712,8 @@ another_hunk (enum diff difftype, bool rev)
+ malformed ();
+ }
+ context++;
+- chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
++ chars_read -= (1 < chars_read && fillsrc == p_ptrn_lines
++ && incomplete_line ());
+ p_Char[fillsrc] = ch;
+ p_line[fillsrc] = s;
+ p_len[fillsrc++] = chars_read;
+@@ -1725,7 +1727,8 @@ another_hunk (enum diff difftype, bool rev)
+ p_end = fillsrc-1;
+ malformed ();
+ }
+- chars_read -= filldst == p_end && incomplete_line ();
++ chars_read -= (1 < chars_read && filldst == p_end
++ && incomplete_line ());
+ p_Char[filldst] = ch;
+ p_line[filldst] = s;
+ p_len[filldst++] = chars_read;
+@@ -1808,7 +1811,8 @@ another_hunk (enum diff difftype, bool rev)
+ fatal (("'<' followed by space or tab expected"
+ " at line %td of patch"),
+ p_input_line);
+- chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
++ chars_read -= 2 + (3 < chars_read && i == p_ptrn_lines
++ && incomplete_line ());
+ p_len[i] = chars_read;
+ p_line[i] = savebuf (patchbuf + 2, chars_read);
+ p_Char[i] = '-';
+@@ -1833,7 +1837,8 @@ another_hunk (enum diff difftype, bool rev)
+ fatal (("'>' followed by space or tab expected"
+ " at line %td of patch"),
+ p_input_line);
+- chars_read -= 2 + (i == p_end && incomplete_line ());
++ chars_read -= 2 + (3 < chars_read && i == p_end
++ && incomplete_line ());
+ p_len[i] = chars_read;
+ p_line[i] = savebuf (patchbuf + 2, chars_read);
+ p_Char[i] = '+';
diff --git a/0005-patch:Port-to-POSIX-ed.patch b/0005-patch:Port-to-POSIX-ed.patch
new file mode 100644
index 0000000..4a2908f
--- /dev/null
+++ b/0005-patch:Port-to-POSIX-ed.patch
@@ -0,0 +1,27 @@
+commit 85c1712fe8f4c9300ae435ef17756ddeeabe17e4
+Author: Paul Eggert <eggert@cs.ucla.edu>
+Date: Tue Apr 21 10:07:40 2026 -0700
+
+ Port to POSIX ‘ed’
+
+ * src/pch.c (do_ed_script): Use ‘ed -s’, not ‘ed -’.
+ All modern ‘ed’ implementations support POSIX’s -s option
+ but at least one (which I don’t remember, but someone reported this)
+ does not support the old Unix ‘ed -’.
+
+diff --git a/src/pch.c b/src/pch.c
+index b83253c..6274b65 100644
+--- a/src/pch.c
++++ b/src/pch.c
+@@ -2381,9 +2381,9 @@ do_ed_script (char *input_name, struct outfile *output, FILE *ofp)
+ pfatal ("Failed to duplicate standard input");
+ assert (output_name[0] != '!' && output_name[0] != '-');
+ idx_t output_namelen = quote_system_arg (nullptr, output_name);
+- char *command = ximalloc (sizeof (EDITOR_PROGRAM " - ") + output_namelen);
++ char *command = ximalloc (sizeof (EDITOR_PROGRAM " -s ") + output_namelen);
+ char *p = command;
+- p = stpcpy (p, EDITOR_PROGRAM " - ");
++ p = stpcpy (p, EDITOR_PROGRAM " -s ");
+ p += quote_system_arg (p, output_name);
+ *p = '\0';
+ int status = systemic (command);
diff --git a/0006-patch:Dont-infloop-on-null-ranges.patch b/0006-patch:Dont-infloop-on-null-ranges.patch
new file mode 100644
index 0000000..f3d900f
--- /dev/null
+++ b/0006-patch:Dont-infloop-on-null-ranges.patch
@@ -0,0 +1,25 @@
+commit faba04ef4f2b410257f76c1b9dc85e350929c4b9
+Author: Paul Eggert <eggert@cs.ucla.edu>
+Date: Tue Apr 21 13:16:10 2026 -0700
+
+ Don’t infloop on null ranges
+
+ Problem reported by Michał Majchrowicz.
+ * src/patch.c (locate_hunk): Don’t attempt to optimize
+ matches of a null range. Instead, apply all the checks
+ we apply to non-null ranges.
+
+diff --git a/src/patch.c b/src/patch.c
+index 16aa5f5..0985af0 100644
+--- a/src/patch.c
++++ b/src/patch.c
+@@ -1170,9 +1170,6 @@ locate_hunk (idx_t fuzz)
+ ptrdiff_t max_offset = MAX (max_pos_offset, max_neg_offset);
+ ptrdiff_t min_offset;
+
+- if (!pat_lines) /* null range matches always */
+- return first_guess;
+-
+ /* Do not try lines <= 0. */
+ if (first_guess <= max_neg_offset)
+ max_neg_offset = first_guess - 1;
diff --git a/0007-patch:Remove-symlink-caching.patch b/0007-patch:Remove-symlink-caching.patch
new file mode 100644
index 0000000..cb00f37
--- /dev/null
+++ b/0007-patch:Remove-symlink-caching.patch
@@ -0,0 +1,72 @@
+commit 51bb61305c2b5c14ffc62787d2f537ddfbf6374f
+Author: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
+Date: Fri May 15 01:17:14 2026 +0200
+
+ Remove symlink caching
+
+ * src/safe.c (traverse_another_path): No longer cache resolved symlinks.
+
+diff --git a/src/safe.c b/src/safe.c
+index 532fbfb..c40657f 100644
+--- a/src/safe.c
++++ b/src/safe.c
+@@ -467,7 +467,6 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ struct cached_dirfd *dir = &cwd;
+ struct symlink *stack = nullptr;
+ idx_t steps = count_path_components (path);
+- struct cached_dirfd *traversed_symlink = nullptr;
+
+ INIT_LIST_HEAD (&cwd.children);
+
+@@ -488,7 +487,6 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ {
+ struct cached_dirfd *entry;
+ struct symlink *symlink = nullptr;
+- char *prev = path;
+
+ entry = traverse_next (dir, stack ? &stack->path : &path, keepfd, &symlink);
+ if (! entry)
+@@ -501,14 +499,6 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ goto fail;
+ }
+ dir = entry;
+- if (! stack && symlink)
+- {
+- const char *p = prev;
+- while (*p && ! ISSLASH (*p))
+- p++;
+- char *name = ximemdup0 (prev, p - prev);
+- traversed_symlink = new_cached_dirfd (dir, name, DIRFD_INVALID);
+- }
+ if (stack && ! *stack->path)
+ pop_symlink (&stack);
+ if (symlink && *symlink->path)
+@@ -523,19 +513,6 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ }
+ else if (symlink)
+ pop_symlink (&symlink);
+- if (traversed_symlink && ! stack)
+- {
+- traversed_symlink->fd =
+- entry->fd == AT_FDCWD ? AT_FDCWD : dup (entry->fd);
+- if (traversed_symlink->fd < 0)
+- free_cached_dirfd (traversed_symlink);
+- else
+- {
+- insert_cached_dirfd (traversed_symlink, keepfd);
+- list_add (&traversed_symlink->lru_link, &lru_list);
+- }
+- traversed_symlink = nullptr;
+- }
+ }
+ *pathname = last;
+ if (debug & 32)
+@@ -550,8 +527,6 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ return put_path (dir);
+
+ fail:
+- if (traversed_symlink)
+- free_cached_dirfd (traversed_symlink);
+ put_path (dir);
+ while (stack)
+ pop_symlink (&stack);
diff --git a/0008-patch:Absolute-in-tree-symlink-target-resolved-relative-to-symlink-parent.patch b/0008-patch:Absolute-in-tree-symlink-target-resolved-relative-to-symlink-parent.patch
new file mode 100644
index 0000000..eb32be0
--- /dev/null
+++ b/0008-patch:Absolute-in-tree-symlink-target-resolved-relative-to-symlink-parent.patch
@@ -0,0 +1,150 @@
+commit a2b192295d7046bafc18d54973436bb3faa659d7
+Author: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
+Date: Fri May 15 01:12:04 2026 +0200
+
+ Absolute in-tree symlink target resolved relative to symlink parent
+
+ When resolving an absolute symlink that points back into patch's working
+ directory, patch resolved the remainder of the symlink relative to the
+ directory containing the symlink rather than the working directory. With
+ symlinks in subdirectories, this can lead to patching the wrong file.
+ * src/safe.c (struct symlink): Store the cached_dirfd a symlink resolves to.
+ (cwd): Turn into a global variable that can be accessed from read-symlink().
+ (read_symlink): Pass the current cached_dirfd and return the cached_dirfd the
+ symlink needs to be resolved in.
+ (traverse_next): Continue traversal in the directory returned by
+ read_symlink().
+ * tests/symlinks: Add absolute symlink test case.
+
+ This closes bug #68311:
+ https://savannah.gnu.org/bugs/?68311
+
+diff --git a/src/safe.c b/src/safe.c
+index c40657f..273133f 100644
+--- a/src/safe.c
++++ b/src/safe.c
+@@ -286,6 +286,7 @@ count_path_components (const char *path)
+ /* A symlink to resolve. */
+ struct symlink {
+ struct symlink *prev;
++ struct cached_dirfd *dir;
+ char *path;
+ };
+
+@@ -302,10 +303,15 @@ static void pop_symlink (struct symlink **stack)
+ free (top);
+ }
+
++static struct cached_dirfd cwd = {
++ .children = LIST_HEAD_INIT(cwd.children),
++ .fd = AT_FDCWD,
++};
++
+ static int cwd_stat_errno = -1;
+ static struct stat cwd_stat;
+
+-static struct symlink *read_symlink(int dirfd, const char *name)
++static struct symlink *read_symlink(struct cached_dirfd *dir, const char *name)
+ {
+ int saved_errno = errno;
+ struct stat st;
+@@ -313,7 +319,7 @@ static struct symlink *read_symlink(int dirfd, const char *name)
+ char *buffer;
+ ssize_t ret;
+
+- if (fstatat (dirfd, name, &st, AT_SYMLINK_NOFOLLOW)
++ if (fstatat (dir->fd, name, &st, AT_SYMLINK_NOFOLLOW)
+ || ! S_ISLNK (st.st_mode))
+ {
+ errno = saved_errno;
+@@ -324,10 +330,11 @@ static struct symlink *read_symlink(int dirfd, const char *name)
+ xalloc_die ();
+ symlink = ximalloc (symlinksize);
+ buffer = (char *)(symlink + 1);
+- ret = readlinkat (dirfd, name, buffer, st.st_size);
++ ret = readlinkat (dir->fd, name, buffer, st.st_size);
+ if (ret <= 0)
+ goto fail;
+ buffer[ret] = 0;
++ symlink->dir = dir;
+ symlink->path = buffer;
+ if (ISSLASH (*buffer))
+ {
+@@ -355,6 +362,7 @@ static struct symlink *read_symlink(int dirfd, const char *name)
+ {
+ while (ISSLASH (*end))
+ end++;
++ symlink->dir = &cwd;
+ symlink->path = end;
+ return symlink;
+ }
+@@ -378,7 +386,7 @@ fail:
+ }
+
+ /* Resolve the next path component in PATH inside DIR. If it is a symlink,
+- read it and returned it in TOP. */
++ read it and return it in SYMLINK. */
+ static struct cached_dirfd *
+ traverse_next (struct cached_dirfd *dir, char **path, int keepfd,
+ struct symlink **symlink)
+@@ -417,9 +425,12 @@ traverse_next (struct cached_dirfd *dir, char **path, int keepfd,
+ /* NetBSD 6.1: Inappropriate file type or format. */)
+ || errno == ENOTDIR)
+ {
+- *symlink = read_symlink (dir->fd, *path);
++ *symlink = read_symlink (dir, *path);
+ if (*symlink)
+- entry = dir;
++ {
++ entry = (*symlink)->dir;
++ (*symlink)->dir = nullptr;
++ }
+ errno = ELOOP;
+ }
+ }
+@@ -459,17 +470,11 @@ traverse_another_path (char **pathname, bool reject_nl, int keepfd)
+ if (unsafe || last == path || IS_ABSOLUTE_FILE_NAME (path))
+ return AT_FDCWD;
+
+- static struct cached_dirfd cwd = {
+- .fd = AT_FDCWD,
+- };
+-
+ intmax_t misses = dirfd_cache_misses;
+ struct cached_dirfd *dir = &cwd;
+ struct symlink *stack = nullptr;
+ idx_t steps = count_path_components (path);
+
+- INIT_LIST_HEAD (&cwd.children);
+-
+ if (steps > MAX_PATH_COMPONENTS)
+ {
+ errno = ELOOP;
+diff --git a/tests/symlinks b/tests/symlinks
+index 53afa56..3ca2439 100644
+--- a/tests/symlinks
++++ b/tests/symlinks
+@@ -435,3 +435,23 @@ ncheck 'ln -sf d l'
+ check 'patch -p1 -i l/ab.diff' <<EOF
+ patching file foo
+ EOF
++
++cat > wrong-base.diff <<EOF
++--- d1/link/target
+++++ d1/link/target
++@@ -1 +1 @@
++-old
+++new
++EOF
++
++mkdir -p sub d1
++echo old > sub/target
++ln -s "$PWD/sub" d1/link
++
++check 'patch -p0 < wrong-base.diff' <<EOF
++patching file d1/link/target
++EOF
++
++check 'cat sub/target' <<EOF
++new
++EOF
diff --git a/patch.spec b/patch.spec
index 09aa54f..ac2a1fd 100644
--- a/patch.spec
+++ b/patch.spec
@@ -3,10 +3,19 @@
Summary: Utility for modifying/upgrading files
Name: patch
Version: 2.8
-Release: 5%{?dist}
+Release: 6%{?dist}
License: GPL-3.0-or-later
URL: https://savannah.gnu.org/projects/patch/
Source: https://ftp.gnu.org/gnu/patch/patch-%{version}.tar.xz
+Patch: 0001-patch:Add-some-missing-filename-quoting.patch
+Patch: 0002-patch:Reject-empty-filenames.patch
+Patch: 0003-patch:Skip-read-only-check-when-output-file-specified.patch
+Patch: 0004-patch:Avoid-null-pointer-derefence-with-bad-hunks.patch
+Patch: 0005-patch:Port-to-POSIX-ed.patch
+Patch: 0006-patch:Dont-infloop-on-null-ranges.patch
+Patch: 0007-patch:Remove-symlink-caching.patch
+Patch: 0008-patch:Absolute-in-tree-symlink-target-resolved-relative-to-symlink-parent.patch
+
BuildRequires: make
BuildRequires: gcc
BuildRequires: libselinux-devel
@@ -49,6 +58,11 @@ make check
%{_mandir}/*/*
%changelog
+* Tue Sep 29 2026 Than Ngo <than@redhat.com> - 2.8-6
+- Bugfix update
+ * Avoid null pointer derefence with bad hunks
+ * Don’t infloop on null ranges
+
* Thu Jul 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 2.8-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
reply other threads:[~2026-09-29 15:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179069644712.1.10710172879371239946.rpms-patch-ca4e7786976f@fedoraproject.org \
--to=than@redhat.com \
--cc=git-commits@fedoraproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox