1 |
commit: f2e931ec5a047e3b15981c02147a42449c101804 |
2 |
Author: Louis Sautier <sbraz <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jan 8 14:07:10 2020 +0000 |
4 |
Commit: Louis Sautier <sbraz <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jan 8 14:47:05 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f2e931ec |
7 |
|
8 |
app-crypt/rhash: fix another problem with recursive checks |
9 |
|
10 |
Bug: https://github.com/rhash/RHash/issues/106 |
11 |
Package-Manager: Portage-2.3.84, Repoman-2.3.20 |
12 |
Signed-off-by: Louis Sautier <sbraz <AT> gentoo.org> |
13 |
|
14 |
.../rhash/files/rhash-1.3.9-rc-segfault.patch | 243 +++++++++++++++++++-- |
15 |
...rhash-1.3.9-r1.ebuild => rhash-1.3.9-r2.ebuild} | 8 +- |
16 |
2 files changed, 229 insertions(+), 22 deletions(-) |
17 |
|
18 |
diff --git a/app-crypt/rhash/files/rhash-1.3.9-rc-segfault.patch b/app-crypt/rhash/files/rhash-1.3.9-rc-segfault.patch |
19 |
index 90a1efecbb1..a2052c67bbf 100644 |
20 |
--- a/app-crypt/rhash/files/rhash-1.3.9-rc-segfault.patch |
21 |
+++ b/app-crypt/rhash/files/rhash-1.3.9-rc-segfault.patch |
22 |
@@ -1,25 +1,230 @@ |
23 |
-From 198e62063ed817357204284a15f95ffc7230044c Mon Sep 17 00:00:00 2001 |
24 |
-From: Aleksey <rhash.admin@×××××.com> |
25 |
-Date: Thu, 2 Jan 2020 21:16:51 +0300 |
26 |
-Subject: [PATCH] fix segfault on rhash -rc |
27 |
- |
28 |
---- |
29 |
- file.c | 5 +++-- |
30 |
- 1 file changed, 3 insertions(+), 2 deletions(-) |
31 |
- |
32 |
+diff --git a/ChangeLog b/ChangeLog |
33 |
+index 8537968..9724c9d 100644 |
34 |
+--- a/ChangeLog |
35 |
++++ b/ChangeLog |
36 |
+@@ -1,3 +1,7 @@ |
37 |
++Tue 07 Jan 2020 Aleksey |
38 |
++ * Bugfix: restore behavior of 'rhash -rc' to be the same as in v1.3.8 |
39 |
++ * Bugfix: fix a segfault and memory errors |
40 |
++ |
41 |
+ Sat 14 Dec 2019 Aleksey |
42 |
+ * === Version 1.3.9 === |
43 |
+ |
44 |
+diff --git a/calc_sums.c b/calc_sums.c |
45 |
+index a76c8c9..0f25224 100644 |
46 |
+--- a/calc_sums.c |
47 |
++++ b/calc_sums.c |
48 |
+@@ -535,6 +535,7 @@ int check_hash_file(file_t* file, int chdir) |
49 |
+ log_error_msg_file_t(_("file is binary: %s\n"), file); |
50 |
+ if (fd != stdin) |
51 |
+ fclose(fd); |
52 |
++ file_cleanup(&parent_dir); |
53 |
+ return -1; |
54 |
+ } |
55 |
+ |
56 |
+@@ -586,6 +587,7 @@ int check_hash_file(file_t* file, int chdir) |
57 |
+ rhash_data.miss++; |
58 |
+ rhash_data.processed++; |
59 |
+ } |
60 |
++ file_cleanup(&parent_dir); |
61 |
+ time = rsh_timer_stop(&timer); |
62 |
+ |
63 |
+ if (res >= -1 && (rsh_fprintf(rhash_data.out, "%s\n", str_set(buf, '-', 80)) < 0 || |
64 |
diff --git a/file.c b/file.c |
65 |
-index 6f593f9..0d18f45 100644 |
66 |
+index 6f593f9..2f0eb2a 100644 |
67 |
--- a/file.c |
68 |
+++ b/file.c |
69 |
-@@ -361,8 +361,9 @@ int file_init_by_print_path(file_t* file, file_t* prepend_dir, const char* print |
70 |
- const char* path = make_path(prepend_dir->real_path, print_path, 0); |
71 |
- file_init(file, path, init_flags & ~FileInitReusePath); |
72 |
+@@ -266,7 +266,7 @@ static int detect_path_encoding(file_t* file, wchar_t* dir_path, const char* pri |
73 |
+ int i; |
74 |
+ assert(file && !file->real_path); |
75 |
+ file->mode &= ~FileMaskStatBits; |
76 |
+- if (!dir_path && ascii) |
77 |
++ if (ascii) |
78 |
+ file->mode |= FileIsAsciiPrintPath; |
79 |
+ /* detect encoding in two or four steps */ |
80 |
+ for (i = 0; i < 4; i += step) { |
81 |
+@@ -333,45 +333,39 @@ int file_init_by_print_path(file_t* file, file_t* prepend_dir, const char* print |
82 |
+ #ifdef _WIN32 |
83 |
+ { |
84 |
+ const char** primary_path; |
85 |
+- const char* dir_primary_path; |
86 |
+ wchar_t* dir_path = (prepend_dir && !IS_DOT_TSTR(prepend_dir->real_path) ? prepend_dir->real_path : NULL); |
87 |
+ int encoding = detect_path_encoding(file, dir_path, print_path, init_flags); |
88 |
+ if (encoding < 0) |
89 |
+ return -1; |
90 |
+ if (encoding == 0) { |
91 |
+ primary_path = &file->print_path; |
92 |
+- dir_primary_path = (prepend_dir ? file_get_print_path(prepend_dir, FPathUtf8) : NULL); |
93 |
+ } else { |
94 |
+ primary_path = &file->native_path; |
95 |
+- dir_primary_path = (prepend_dir ? file_get_print_path(prepend_dir, FPathNative) : NULL); |
96 |
+ } |
97 |
+- if ((!dir_primary_path || IS_DOT_TSTR(dir_primary_path)) && |
98 |
+- (init_flags & (FileInitReusePath | FileInitUpdatePrintPathLastSlash)) == FileInitReusePath) { |
99 |
++ if ((init_flags & (FileInitReusePath | FileInitUpdatePrintPathLastSlash)) == FileInitReusePath) { |
100 |
+ *primary_path = print_path; |
101 |
+ file->mode |= (encoding == 0 ? FileDontFreePrintPath : FileDontFreeNativePath); |
102 |
+ } else { |
103 |
+- *primary_path = make_path(dir_primary_path, print_path, 1); |
104 |
++ *primary_path = rsh_strdup(print_path); |
105 |
+ } |
106 |
+- return 0; |
107 |
+ } |
108 |
+ #else |
109 |
+ if (!prepend_dir || IS_DOT_STR(prepend_dir->real_path)) { |
110 |
+- file_init(file, print_path, init_flags); |
111 |
++ file_init(file, print_path, init_flags & (FileInitReusePath | FileMaskModeBits)); |
112 |
+ } else { |
113 |
+- const char* path = make_path(prepend_dir->real_path, print_path, 0); |
114 |
+- file_init(file, path, init_flags & ~FileInitReusePath); |
115 |
++ file->real_path = make_path(prepend_dir->real_path, print_path, 0); |
116 |
++ file->mode = init_flags & FileMaskModeBits; |
117 |
} |
118 |
- if (!prepend_dir || IS_DOT_STR(prepend_dir->print_path) || |
119 |
- (!prepend_dir->print_path && opt.path_separator != ALIEN_PATH_SEPARATOR)) { |
120 |
-+ if (!prepend_dir || (prepend_dir->print_path ? |
121 |
-+ IS_DOT_STR(prepend_dir->print_path) : |
122 |
-+ opt.path_separator != ALIEN_PATH_SEPARATOR)) { |
123 |
- if ((init_flags & FileInitReusePath) != 0) { |
124 |
- file->print_path = print_path; |
125 |
- file->mode |= FileDontFreePrintPath; |
126 |
+- if ((init_flags & FileInitReusePath) != 0) { |
127 |
+- file->print_path = print_path; |
128 |
+- file->mode |= FileDontFreePrintPath; |
129 |
+- } else |
130 |
+- file->print_path = rsh_strdup(print_path); |
131 |
++ assert(file->print_path == NULL); |
132 |
++ if ((init_flags & (FileInitReusePath | FileInitUpdatePrintPathLastSlash)) == FileInitReusePath) { |
133 |
++ file->print_path = print_path; |
134 |
++ file->mode |= FileDontFreePrintPath; |
135 |
+ } else { |
136 |
+- file->print_path = make_path(file_get_print_path(prepend_dir, FPathPrimaryEncoding), print_path, 1); |
137 |
++ file->print_path = rsh_strdup(print_path); |
138 |
+ } |
139 |
+ #endif |
140 |
++ /* note: flag FileInitUpdatePrintPathLastSlash is used only with file_init() */ |
141 |
++ assert((init_flags & FileInitUpdatePrintPathLastSlash) == 0); |
142 |
+ if ((init_flags & (FileInitRunFstat | FileInitRunLstat)) && |
143 |
+ file_stat(file, (init_flags & FileInitRunLstat)) < 0) |
144 |
+ return -1; |
145 |
+@@ -544,9 +538,10 @@ static char* get_modified_path(const char* path, const char* str, int operation) |
146 |
+ end_pos = strlen(path); |
147 |
+ start_pos = (end_pos > 0 ? end_pos - 1 : 0); |
148 |
+ for (; start_pos > 0 && !IS_ANY_SLASH(path[start_pos]); start_pos--); |
149 |
+- for (; start_pos > 0 && IS_ANY_SLASH(path[start_pos]); start_pos--); |
150 |
+- if (start_pos == 0) |
151 |
++ if (start_pos == 0 && !IS_ANY_SLASH(path[start_pos])) |
152 |
+ return rsh_strdup("."); |
153 |
++ for (; start_pos > 0 && IS_ANY_SLASH(path[start_pos]); start_pos--); |
154 |
++ start_pos++; |
155 |
+ } else { |
156 |
+ char* point = strrchr(path, '.'); |
157 |
+ if (!point) |
158 |
+@@ -580,9 +575,10 @@ static tpath_t get_modified_tpath(ctpath_t path, const char* str, int operation) |
159 |
+ end_pos = wcslen(path); |
160 |
+ start_pos = (end_pos > 0 ? end_pos - 1 : 0); |
161 |
+ for (; start_pos > 0 && !IS_ANY_TSLASH(path[start_pos]); start_pos--); |
162 |
+- for (; start_pos > 0 && IS_ANY_TSLASH(path[start_pos]); start_pos--); |
163 |
+- if (start_pos == 0) |
164 |
++ if (start_pos == 0 && !IS_ANY_TSLASH(path[start_pos])) |
165 |
+ return rsh_wcsdup(L"."); |
166 |
++ for (; start_pos > 0 && IS_ANY_TSLASH(path[start_pos]); start_pos--); |
167 |
++ start_pos++; |
168 |
+ } else { |
169 |
+ rsh_tchar* point = wcsrchr(path, L'.'); |
170 |
+ if (!point) |
171 |
+diff --git a/hash_check.c b/hash_check.c |
172 |
+index 1f9c936..582a09d 100644 |
173 |
+--- a/hash_check.c |
174 |
++++ b/hash_check.c |
175 |
+@@ -210,9 +210,9 @@ static int detect_hash_type(char** ptr, char* end, int* p_len) |
176 |
+ } else { |
177 |
+ /* search backward (but no more then 129 symbols) */ |
178 |
+ if ((p - end) >= 129) end = p - 129; |
179 |
+- for (; p >= end && p[-1] == '='; eq_num++, p--) |
180 |
++ for (; p > end && p[-1] == '='; eq_num++, p--) |
181 |
+ char_type = FmtBase64; |
182 |
+- for (; p >= end && (next_type &= test_hash_char(p[-1])); len++, p--) |
183 |
++ for (; p > end && (next_type &= test_hash_char(p[-1])); len++, p--) |
184 |
+ char_type = next_type; |
185 |
+ } |
186 |
+ if ((char_type & FmtBase64) != 0) |
187 |
+diff --git a/tests/test_rhash.sh b/tests/test_rhash.sh |
188 |
+index 8c6e40d..db41b19 100755 |
189 |
+--- a/tests/test_rhash.sh |
190 |
++++ b/tests/test_rhash.sh |
191 |
+@@ -84,12 +84,9 @@ remove_tmpdir() |
192 |
+ trap remove_tmpdir EXIT |
193 |
+ |
194 |
+ # prepare test files |
195 |
+-SUBDIR=$RHASH_TMP/dir1 |
196 |
+-mkdir $RHASH_TMP $SUBDIR || die "Unable to create tmp dir." |
197 |
++mkdir $RHASH_TMP || die "Unable to create tmp dir." |
198 |
++cp "$SCRIPT_DIR/test1K.data" $RHASH_TMP/test1K.data |
199 |
+ cd "$RHASH_TMP" |
200 |
+-cp "$SCRIPT_DIR/test1K.data" test1K.data |
201 |
+-FILE_A=dir1/a.txt |
202 |
+-printf "a" > $FILE_A |
203 |
+ |
204 |
+ # get the list of supported hash options |
205 |
+ HASHOPT="`$rhash --list-hashes|sed 's/ .*$//;/[^23]-/s/-\([0-9R]\)/\1/'|tr A-Z a-z`" |
206 |
+@@ -207,14 +204,13 @@ TEST_EXPECTED="(message) 1 E8B7BE43 5c334qy BTAXLOOA6G3KQMODTHRGS5ZGME hvfkN/qlp |
207 |
+ check "$TEST_RESULT" "$TEST_EXPECTED" |
208 |
+ |
209 |
+ new_test "test %u modifier: " |
210 |
+-cp $FILE_A "dir1/=@+.txt" |
211 |
++mkdir dir1 && printf "a" > "dir1/=@+.txt" |
212 |
+ TEST_RESULT=$( $rhash -p '%uf %Uf %up %Up %uxc %uxC %ubc %ubC\n' "dir1/=@+.txt" ) |
213 |
+ TEST_EXPECTED="%3d%40%2b.txt %3D%40%2B.txt dir1%2f%3d%40%2b.txt dir1%2F%3D%40%2B.txt e8b7be43 E8B7BE43 5c334qy 5C334QY" |
214 |
+ check "$TEST_RESULT" "$TEST_EXPECTED" . |
215 |
+ TEST_RESULT=$( $rhash -p '%uBc %UBc %Bc %u@c %U@c\n' -m "a" ) |
216 |
+ TEST_EXPECTED="6Le%2bQw%3d%3d 6Le%2BQw%3D%3D 6Le+Qw== %e8%b7%beC %E8%B7%BEC" |
217 |
+ check "$TEST_RESULT" "$TEST_EXPECTED" |
218 |
+-rm -f "dir1/=@+.txt" |
219 |
+ |
220 |
+ new_test "test special characters: " |
221 |
+ TEST_RESULT=$( $rhash -p '\63\1\277\x0f\x1\t\\ \x34\r' -m "" ) |
222 |
+@@ -252,7 +248,9 @@ TEST_RESULT=$( $rhash --simple -a test1K.data | $rhash -vc - 2>/dev/null | grep |
223 |
+ match "$TEST_RESULT" "^test1K.data *OK" |
224 |
+ |
225 |
+ new_test "test checking magnet link: " |
226 |
+-TEST_RESULT=$( $rhash --magnet -a test1K.data | $rhash -vc - 2>&1 | grep test1K.data ) |
227 |
++# also test that '--check' verifies files in the current directory |
228 |
++mkdir magnet_dir && $rhash --magnet -a test1K.data > magnet_dir/t.magnet |
229 |
++TEST_RESULT=$( $rhash -vc magnet_dir/t.magnet 2>&1 | grep test1K.data ) |
230 |
+ TEST_EXPECTED="^test1K.data *OK" |
231 |
+ match "$TEST_RESULT" "$TEST_EXPECTED" |
232 |
+ |
233 |
+@@ -283,6 +281,20 @@ TEST_RESULT=$( $rhash --simple --embed-crc --embed-crc-delimiter=_ 'test.data' 2 |
234 |
+ check "$TEST_RESULT" "d3d99e8b test_[D3D99E8B].data" |
235 |
+ rm 'test_[D3D99E8B].data' 'test_[D3D99E8C].data' |
236 |
+ |
237 |
++new_test "test checking recursively: " |
238 |
++mkdir -p check/a && cp test1K.data check/a/b.data |
239 |
++echo "a/b.data B70B4C26" > check/b.sfv |
240 |
++TEST_RESULT=$( $rhash -Crc check/ | grep b.data ) |
241 |
++match "$TEST_RESULT" "^a/b.data *OK" . |
242 |
++echo "B70B4C26" > check/a/b.data.crc32 |
243 |
++TEST_RESULT=$( $rhash --crc-accept=.crc32 -Crc check/a | grep "data.*OK" ) |
244 |
++match "$TEST_RESULT" "^check/a.b.data *OK" . |
245 |
++# test that hash-files specified explicitly by command line are checked |
246 |
++# in the current directory even with '--recursive' option |
247 |
++echo "test1K.data B70B4C26" > check/t.sfv |
248 |
++TEST_RESULT=$( $rhash -Crc check/t.sfv | grep "data.*OK" ) |
249 |
++match "$TEST_RESULT" "^test1K.data *OK" |
250 |
++ |
251 |
+ new_test "test wrong sums detection: " |
252 |
+ $rhash -p '%c\n%m\n%e\n%h\n%g\n%t\n%a\n%w\n' -m WRONG > t.sum |
253 |
+ TEST_RESULT=$( $rhash -vc t.sum 2>&1 | grep 'OK' ) |
254 |
+@@ -290,8 +302,7 @@ check "$TEST_RESULT" "" |
255 |
+ rm t.sum |
256 |
+ |
257 |
+ new_test "test *accept options: " |
258 |
+-rm -rf test_dir/ |
259 |
+-mkdir -p test_dir && touch test_dir/file.txt test_dir/file.bin |
260 |
++mkdir test_dir && touch test_dir/file.txt test_dir/file.bin |
261 |
+ # correctly handle MIGW posix path conversion |
262 |
+ echo "$MSYSTEM" | grep -q '^MINGW[36][24]' && SLASH=// || SLASH="/" |
263 |
+ # test also --path-separator option |
264 |
+@@ -301,7 +312,6 @@ TEST_RESULT=$( $rhash -rC --simple --accept=.txt --path-separator=\\ test_dir ) |
265 |
+ check "$TEST_RESULT" "00000000 test_dir\\file.txt" . |
266 |
+ TEST_RESULT=$( $rhash -rc --crc-accept=.bin test_dir 2>/dev/null | sed -n '/Verifying/s/-//gp' ) |
267 |
+ match "$TEST_RESULT" "( Verifying test_dir.file\\.bin )" |
268 |
+-rm -rf test_dir/ |
269 |
+ |
270 |
+ new_test "test ignoring of log files: " |
271 |
+ touch t1.out t2.out |
272 |
|
273 |
diff --git a/app-crypt/rhash/rhash-1.3.9-r1.ebuild b/app-crypt/rhash/rhash-1.3.9-r2.ebuild |
274 |
similarity index 88% |
275 |
rename from app-crypt/rhash/rhash-1.3.9-r1.ebuild |
276 |
rename to app-crypt/rhash/rhash-1.3.9-r2.ebuild |
277 |
index e203d68814e..861a75662e4 100644 |
278 |
--- a/app-crypt/rhash/rhash-1.3.9-r1.ebuild |
279 |
+++ b/app-crypt/rhash/rhash-1.3.9-r2.ebuild |
280 |
@@ -32,6 +32,8 @@ S="${WORKDIR}/RHash-${PV}" |
281 |
|
282 |
PATCHES=( |
283 |
"${FILESDIR}"/${P}-nls.patch |
284 |
+ # Fixes for https://github.com/rhash/RHash/issues/104 |
285 |
+ # and https://github.com/rhash/RHash/issues/106 |
286 |
"${FILESDIR}"/${P}-rc-segfault.patch |
287 |
) |
288 |
|
289 |
@@ -69,9 +71,9 @@ multilib_src_configure() { |
290 |
multilib_src_install() { |
291 |
# -j1 needed due to race condition. |
292 |
emake DESTDIR="${D}" -j1 \ |
293 |
- install{,-lib-headers,-pkg-config} \ |
294 |
- $(use nls && echo install-gmo) \ |
295 |
- $(use kernel_Winnt || echo install-lib-so-link) |
296 |
+ install{,-lib-headers,-pkg-config} \ |
297 |
+ $(use nls && echo install-gmo) \ |
298 |
+ $(use kernel_Winnt || echo install-lib-so-link) |
299 |
} |
300 |
|
301 |
multilib_src_test() { |