Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/patch/files/, sys-devel/patch/
Date: Sun, 26 Aug 2018 14:32:42
Message-Id: 1535293938.dedeef3e8b0b5cb7010149efa4e92892fa74ed36.whissi@gentoo
1 commit: dedeef3e8b0b5cb7010149efa4e92892fa74ed36
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Sun Aug 26 14:32:18 2018 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Sun Aug 26 14:32:18 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=dedeef3e
7
8 sys-devel/patch: fix error handling with git-style patches
9
10 Closes: https://bugs.gentoo.org/664640
11 Package-Manager: Portage-2.3.48, Repoman-2.3.10
12
13 ...fix-error-handling-with-git-style-patches.patch | 125 +++++++++++++++++++++
14 sys-devel/patch/patch-2.7.6-r2.ebuild | 36 ++++++
15 2 files changed, 161 insertions(+)
16
17 diff --git a/sys-devel/patch/files/patch-2.7.6-fix-error-handling-with-git-style-patches.patch b/sys-devel/patch/files/patch-2.7.6-fix-error-handling-with-git-style-patches.patch
18 new file mode 100644
19 index 00000000000..a4f127dd7ce
20 --- /dev/null
21 +++ b/sys-devel/patch/files/patch-2.7.6-fix-error-handling-with-git-style-patches.patch
22 @@ -0,0 +1,125 @@
23 +Backport for Gentoo patch-2.7.x.
24 +
25 +https://bugs.gentoo.org/664640
26 +
27 +
28 +Original patch:
29 +Author: Lubomir Rintel <lkundrak@××.sk>
30 +Date: Tue Feb 27 16:52:00 2018 +0100
31 +Subject: Fix error handling with git-style patches
32 +
33 +When an error is encountered in output_files(), the subsequent call to
34 +cleanup() calls back into output_files() resulting in an infinte recursion.
35 +This is trivially reproduced with a git-style patch (which utilizes
36 +output_file_later()) that tries to patch a nonexistent or unreadable
37 +file (see attached test case).
38 +
39 +* src/patch.c: (output_files) clear the files_to_output list before
40 +iterating it, so that recursive calls won't iterate the same files.
41 +* tests/git-error: New test case.
42 +* tests/Makefile.am (TESTS): Add test case.
43 +
44 +Origin: https://lists.gnu.org/archive/html/bug-patch/2018-02/msg00010.html
45 +
46 +--- a/src/patch.c
47 ++++ b/src/patch.c
48 +@@ -1938,8 +1938,12 @@ output_files (struct stat const *st)
49 + {
50 + gl_list_iterator_t iter;
51 + const void *elt;
52 ++ gl_list_t files;
53 +
54 +- iter = gl_list_iterator (files_to_output);
55 ++ files = files_to_output;
56 ++ init_files_to_output ();
57 ++
58 ++ iter = gl_list_iterator (files);
59 + while (gl_list_iterator_next (&iter, &elt, NULL))
60 + {
61 + const struct file_to_output *file_to_output = elt;
62 +@@ -1957,8 +1961,8 @@ output_files (struct stat const *st)
63 + /* Free the list up to here. */
64 + for (;;)
65 + {
66 +- const void *elt2 = gl_list_get_at (files_to_output, 0);
67 +- gl_list_remove_at (files_to_output, 0);
68 ++ const void *elt2 = gl_list_get_at (files, 0);
69 ++ gl_list_remove_at (files, 0);
70 + if (elt == elt2)
71 + break;
72 + }
73 +@@ -1967,7 +1971,7 @@ output_files (struct stat const *st)
74 + }
75 + }
76 + gl_list_iterator_free (&iter);
77 +- gl_list_clear (files_to_output);
78 ++ gl_list_free (files);
79 + }
80 +
81 + /* Fatal exit with cleanup. */
82 +--- a/tests/Makefile.am
83 ++++ b/tests/Makefile.am
84 +@@ -40,6 +40,7 @@ TESTS = \
85 + filename-choice \
86 + git-binary-diff \
87 + git-cleanup \
88 ++ git-error \
89 + garbage \
90 + global-reject-files \
91 + inname \
92 +--- a/tests/Makefile.in
93 ++++ b/tests/Makefile.in
94 +@@ -1316,6 +1316,7 @@ TESTS = \
95 + filename-choice \
96 + git-binary-diff \
97 + git-cleanup \
98 ++ git-error \
99 + garbage \
100 + global-reject-files \
101 + inname \
102 +@@ -1695,6 +1696,13 @@ git-cleanup.log: git-cleanup
103 + --log-file $$b.log --trs-file $$b.trs \
104 + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
105 + "$$tst" $(AM_TESTS_FD_REDIRECT)
106 ++git-error.log: git-error
107 ++ @p='git-error'; \
108 ++ b='git-error'; \
109 ++ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
110 ++ --log-file $$b.log --trs-file $$b.trs \
111 ++ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
112 ++ "$$tst" $(AM_TESTS_FD_REDIRECT)
113 + garbage.log: garbage
114 + @p='garbage'; \
115 + b='garbage'; \
116 +--- /dev/null
117 ++++ b/tests/git-error
118 +@@ -0,0 +1,29 @@
119 ++# Copyright (C) 2018 Free Software Foundation, Inc.
120 ++#
121 ++# Copying and distribution of this file, with or without modification,
122 ++# in any medium, are permitted without royalty provided the copyright
123 ++# notice and this notice are preserved.
124 ++
125 ++. $srcdir/test-lib.sh
126 ++
127 ++require cat
128 ++use_local_patch
129 ++use_tmpdir
130 ++
131 ++cat > f.diff <<EOF
132 ++diff --git a/boo b/boo
133 ++--- /dev/fd/63 2018-02-27 16:32:54.861266246 +0100
134 +++++ /dev/fd/62 2018-02-27 16:32:54.861266246 +0100
135 ++@@ -1 +1 @@
136 ++-abc
137 +++def
138 ++
139 ++EOF
140 ++
141 ++check 'patch .nonexistent < f.diff || echo "Status: $?"' <<EOF
142 ++patching file .nonexistent
143 ++Hunk #1 FAILED at 1.
144 ++1 out of 1 hunk FAILED -- saving rejects to file .nonexistent.rej
145 ++$PATCH: **** Can't reopen file .nonexistent : No such file or directory
146 ++Status: 2
147 ++EOF
148
149 diff --git a/sys-devel/patch/patch-2.7.6-r2.ebuild b/sys-devel/patch/patch-2.7.6-r2.ebuild
150 new file mode 100644
151 index 00000000000..9a973442432
152 --- /dev/null
153 +++ b/sys-devel/patch/patch-2.7.6-r2.ebuild
154 @@ -0,0 +1,36 @@
155 +# Copyright 1999-2018 Gentoo Foundation
156 +# Distributed under the terms of the GNU General Public License v2
157 +
158 +EAPI="6"
159 +
160 +inherit flag-o-matic
161 +
162 +DESCRIPTION="Utility to apply diffs to files"
163 +HOMEPAGE="https://www.gnu.org/software/patch/patch.html"
164 +SRC_URI="mirror://gnu/patch/${P}.tar.xz"
165 +
166 +LICENSE="GPL-3+"
167 +SLOT="0"
168 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
169 +IUSE="static test xattr"
170 +
171 +RDEPEND="xattr? ( sys-apps/attr )"
172 +DEPEND="${RDEPEND}
173 + test? ( sys-apps/ed )"
174 +
175 +PATCHES=(
176 + "${FILESDIR}"/${P}-fix-test-suite.patch
177 + "${FILESDIR}"/${PN}-2.7.6-fix-error-handling-with-git-style-patches.patch
178 +)
179 +
180 +src_configure() {
181 + use static && append-ldflags -static
182 +
183 + local myeconfargs=(
184 + $(use_enable xattr)
185 + --program-prefix="$(use userland_BSD && echo g)"
186 + )
187 + # Do not let $ED mess up the search for `ed` 470210.
188 + ac_cv_path_ED=$(type -P ed) \
189 + econf "${myeconfargs[@]}"
190 +}