Debian Codegraph @

debian/patches/debian-changes

raw
1 Description: Collected Debian patches for xdg-utils
2 Author: Nicholas Guriev <[email protected]>
3
4 The xdg-utils package is maintained in Git rather than maintaining
5 patches as separate files, and separating the patches doesn't seem to
6 be worth the effort. They are therefore all included in this single
7 Debian patch.
8
9 For full commit history and separated commits, see the packaging Git
10 repository.
11
12 ---
13
14 --- a/autotests/Makefile.in
15 +++ b/autotests/Makefile.in
16 @@ -17,8 +17,9 @@ autotest: test
17 remove-failed-tests:
18 rm -f failed-tests
19
20 +export SHELL
21 $(T): remove-failed-tests
22 - @sh $@
23 + @$(SHELL) $@
24
25 clean: remove-failed-tests
26 rm -fr lab
27 --- a/autotests/t-xdg-open.sh
28 +++ b/autotests/t-xdg-open.sh
29 @@ -133,13 +133,6 @@ mock_desktop_file mosaic %u
30 mock_default_app x-scheme-handler/http mosaic
31 test_open_url generic mosaic
32
33 -test_that_it always uses \$BROWSER if set in generic mode
34 -BROWSER=cyberdog
35 -mock_desktop_file mosaic %u
36 -mock_default_app x-scheme-handler/http mosaic
37 -mock mosaic
38 -test_open_url generic cyberdog
39 -
40 test_that_it works with multi-word \$BROWSER commands
41 BROWSER="cyberdog --url %s"
42 test_open_url generic cyberdog --url
43 @@ -150,6 +143,15 @@ mock cyberdog
44 BROWSER="cyberdog --url %s"
45 run generic xdg-open 'http://www.freedesktop.org/; echo BUSTED'
46 assert_run cyberdog --url 'http://www.freedesktop.org/; echo BUSTED'
47 +unmock cyberdog
48 +
49 +test_that_it is not vulnerable to argument injection in URLs when using \
50 + \$BROWSER in generic mode
51 +mock cyberdog
52 +BROWSER="cyberdog --url %s"
53 +run generic xdg-open 'http://www.freedesktop.org/ --evil-option'
54 +assert_run cyberdog --url 'http://www.freedesktop.org/ --evil-option'
55 +unmock cyberdog
56
57 test_that_it opens files in generic mode
58 test_generic_open_file test.txt
59 --- a/autotests/test-lib.sh
60 +++ b/autotests/test-lib.sh
61 @@ -140,6 +140,17 @@ Exec=$*
62 EOF
63 }
64
65 +mock_terminal_app() {
66 + mock "$1"
67 + cat > "$XDG_DATA_DIR/applications/$1.desktop" <<EOF
68 +[Desktop Entry]
69 +Type=Application
70 +Name=$1
71 +Exec=$*
72 +Terminal=true
73 +EOF
74 +}
75 +
76 mock_default_app() {
77 local mimetype="$1" app="$2"
78 local mimeapps=$XDG_CONFIG_HOME/mimeapps.list
79 @@ -183,20 +194,23 @@ run() {
80 local de="$1"
81 shift
82
83 - local cmd="$1"
84 - shift
85 -
86 : > $COMMANDS_RUN
87
88 set_de_ $de
89
90 local trace=
91 + if [ "$DETACH" = 0 ]; then
92 + trace="perl ./ttyon"
93 + elif [ "$DETACH" = 1 ]; then
94 + trace="perl ./ttyoff"
95 + fi
96 + trace="$trace ${SHELL:-/bin/sh}"
97 if [ "$TRACE" = 1 ]; then
98 - trace="sh -x"
99 + trace="$trace -x"
100 fi
101
102 if [ "$TRACE" = 1 ] || [ "$TRACE_RUN" = 1 ]; then
103 - echo "RUN [$de] $cmd $*" >&2
104 + echo "RUN [$de] $*" >&2
105 fi
106
107 env -i \
108 @@ -213,7 +227,8 @@ run() {
109 XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS \
110 DISPLAY=x \
111 BROWSER="$BROWSER" \
112 - $trace ../scripts/$cmd "$@" ||:
113 + TERMINAL="$TERMINAL" \
114 + $trace -c 'exec "$@"' - "$@" ||:
115 }
116
117 echo "* Testing that $COMMAND_TESTED"
118 --- /dev/null
119 +++ b/autotests/ttyoff
120 @@ -0,0 +1,84 @@
121 +#!/usr/bin/perl
122 +
123 +# ttyoff - run command detached from terminal
124 +#
125 +# Copyright 2020, Nicholas Guriev <[email protected]>
126 +#
127 +# Permission is hereby granted, free of charge, to any person obtaining a
128 +# copy of this software and associated documentation files (the "Software"),
129 +# to deal in the Software without restriction, including without limitation
130 +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
131 +# and/or sell copies of the Software, and to permit persons to whom the
132 +# Software is furnished to do so, subject to the following conditions:
133 +#
134 +# The above copyright notice and this permission notice shall be included
135 +# in all copies or substantial portions of the Software.
136 +#
137 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
138 +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
139 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
140 +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
141 +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
142 +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
143 +# OTHER DEALINGS IN THE SOFTWARE.
144 +
145 +=head1 NAME
146 +
147 +ttyoff - run command detached from terminal
148 +
149 +=head1 SYNOPSIS
150 +
151 +B<ttyoff> [B<-a> I<NAME>] [B<-s>] [I<COMMAND>...]
152 +
153 +=head1 DESCRIPTION
154 +
155 +Simple script that detaches itself from the controlling terminal and executes
156 +passed command. The script is primarily intended for running automated tests.
157 +
158 +If no command is specified, current Shell is executed.
159 +
160 +Options:
161 +
162 +=over
163 +
164 +=item B<-a>
165 +
166 +Override the zeroth argument of the command.
167 +
168 +=item B<-s>
169 +
170 +Before proceeding, close standard streams (numbered 0, 1, and 2).
171 +
172 +=back
173 +
174 +=head1 AUTHOR
175 +
176 +Written by Nicholas Guriev on New Year's Eve 2021.
177 +
178 +=head1 SEE ALSO
179 +
180 +tty(4)
181 +
182 +=cut
183 +
184 +
185 +use strict;
186 +use warnings;
187 +
188 +use Getopt::Std;
189 +BEGIN { require "sys/ioctl.ph" }
190 +
191 +$Getopt::Std::STANDARD_HELP_VERSION = 1;
192 +our ($opt_a, $opt_s);
193 +getopts("a:s") or exit 1;
194 +
195 +if (open my $term, "+<", "/dev/tty") {
196 + ioctl $term, TIOCNOTTY, 0 or die $!;
197 +}
198 +if ($opt_s) {
199 + close $_ or die $! for (*STDIN, *STDOUT, *STDERR);
200 +}
201 +unless (@ARGV) {
202 + push @ARGV, $ENV{SHELL} || "/bin/sh";
203 +}
204 +exec { $opt_a or $ARGV[0] } @ARGV or die $!;
205 --- /dev/null
206 +++ b/autotests/ttyon
207 @@ -0,0 +1,130 @@
208 +#!/usr/bin/perl
209 +
210 +# ttyon - run command controlled by fake terminal
211 +#
212 +# Copyright 2021, Nicholas Guriev <[email protected]>
213 +#
214 +# Permission is hereby granted, free of charge, to any person obtaining a
215 +# copy of this software and associated documentation files (the "Software"),
216 +# to deal in the Software without restriction, including without limitation
217 +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
218 +# and/or sell copies of the Software, and to permit persons to whom the
219 +# Software is furnished to do so, subject to the following conditions:
220 +#
221 +# The above copyright notice and this permission notice shall be included
222 +# in all copies or substantial portions of the Software.
223 +#
224 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
225 +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
226 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
227 +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
228 +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
229 +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230 +# OTHER DEALINGS IN THE SOFTWARE.
231 +
232 +=head1 NAME
233 +
234 +ttyon - run command controlled by fake terminal
235 +
236 +=head1 SYNOPSIS
237 +
238 +B<ttyon> [B<-a> I<NAME>] [B<-fs>] [I<COMMAND>...]
239 +
240 +=head1 DESCRIPTION
241 +
242 +Simple script that tries to open a fake controlling terminal and executes
243 +passed command. The script is primarily intended for running automated tests.
244 +
245 +If no command is specified, current Shell is executed.
246 +
247 +Options:
248 +
249 +=over
250 +
251 +=item B<-a>
252 +
253 +Override the zeroth argument of the command.
254 +
255 +=item B<-f>
256 +
257 +Never avoid wasted forks.
258 +
259 +=item B<-s>
260 +
261 +Connect standard streams (numbered 0, 1, and 2) to the opened terminal.
262 +
263 +=back
264 +
265 +=head1 AUTHOR
266 +
267 +Written by Nicholas Guriev on New Year's holidays 2021.
268 +
269 +=head1 SEE ALSO
270 +
271 +pts(4), ioctl_tty(2)
272 +
273 +=cut
274 +
275 +
276 +use strict;
277 +use warnings;
278 +
279 +use Getopt::Std;
280 +use Fcntl;
281 +use POSIX ();
282 +BEGIN { require "sys/ioctl.ph" }
283 +
284 +sub do_switch {
285 + my $child = fork;
286 + die $! unless defined $child;
287 + if ($child) {
288 + waitpid $child, 0 or die $!;
289 + kill $? & 127, $$ if $? & 127;
290 + POSIX::_exit $? >> 8; # Perl's cleaning causes unwanted SIGHUP.
291 + }
292 +}
293 +
294 +# Some constants from ioctl.ph have incorrect value due to missing %sizeof hash.
295 +# Apply a workaround suggested by Celelibi at https://bugs.debian.org/190887#26
296 +our %sizeof = (int => length pack "i!", 0);
297 +
298 +$Getopt::Std::STANDARD_HELP_VERSION = 1;
299 +our ($opt_a, $opt_f, $opt_s);
300 +getopts("a:fs") or exit 1;
301 +
302 +my $term;
303 +if ($opt_f or not open $term, "+<", "/dev/tty") {
304 + # Become a session leader.
305 + if ($opt_f or POSIX::setsid() < 0) {
306 + do_switch;
307 + POSIX::setsid() > 0 or die $!;
308 + }
309 +
310 + # Open a new terminal pair trough a multiplexor and treat its descriptor as
311 + # system file to not auto-close it by master process.
312 + local $^F = 3;
313 + open $term, "+<", "/dev/ptmx" or die $!;
314 +
315 + # Equivalent of unlockpt(3) which is not provided by the POSIX package.
316 + my $buf = pack "i!", 0;
317 + ioctl $term, TIOCSPTLCK, $buf or die $!;
318 +
319 + # Set the new terminal as controlling of us.
320 + ioctl $term, TIOCSCTTY, 0 or die $!;
321 +}
322 +do_switch if $opt_f;
323 +
324 +if ($opt_s and $term) {
325 + for my $stream (*STDIN, *STDOUT, *STDERR) {
326 + # Reopen via an equivalent of ptsname(3).
327 + close $stream or die $!;
328 + my $fd = ioctl $term, TIOCGPTPEER, O_RDWR or die $!;
329 + open $stream, "+<&=", $fd or die $!;
330 + }
331 +}
332 +close $term or die $! if $opt_f;
333 +
334 +unless (@ARGV) {
335 + push @ARGV, $ENV{SHELL} || "/bin/sh";
336 +}
337 +exec { $opt_a or $ARGV[0] } @ARGV or die $!;
338 --- a/scripts/xdg-mime.in
339 +++ b/scripts/xdg-mime.in
340 @@ -306,6 +306,7 @@ make_default_generic()
341 DEBUG 2 "make_default_generic $1 $2"
342 DEBUG 1 "Updating $out_file"
343 [ -f "$out_file" ] || touch "$out_file"
344 + [ -d "$xdg_config_home" ] || mkdir -p "$xdg_config_home"
345 awk -v mimetype="$2" -v application="$1" '
346 BEGIN {
347 prefix=mimetype "="
348 --- a/scripts/xdg-open.in
349 +++ b/scripts/xdg-open.in
350 @@ -420,13 +420,9 @@ open_generic_xdg_x_scheme_handler()
351 fi
352 }
353
354 -has_single_argument()
355 -{
356 - test $# = 1
357 -}
358 -
359 open_envvar()
360 {
361 + local url="$1"
362 local oldifs="$IFS"
363 local browser
364
365 @@ -439,14 +435,18 @@ open_envvar()
366 fi
367
368 if echo "$browser" | grep -q %s; then
369 - # Avoid argument injection.
370 + # Use loop to insert URL for avoid argument injection.
371 # See https://bugs.freedesktop.org/show_bug.cgi?id=103807
372 # URIs don't have IFS characters spaces anyway.
373 # shellcheck disable=SC2086,SC2091,SC2059
374 # All the scary things here are intentional
375 - has_single_argument $1 && $(printf "$browser" "$1")
376 + shift $#
377 + for arg in $browser; do
378 + set -- "$@" "$(printf -- "$arg" "$url")"
379 + done
380 + "$@"
381 else
382 - $browser "$1"
383 + $browser "$url"
384 fi
385
386 if [ $? -eq 0 ]; then
387 --- a/scripts/xdg-screensaver.in
388 +++ b/scripts/xdg-screensaver.in
389 @@ -461,8 +461,9 @@ my $x = X11::Protocol->new();
390 my $named_window_id = hex($window_id);
391 my $window_name;
392 while (1) {
393 - ($window_name) = $x->GetProperty($named_window_id, $x->atom("WM_NAME"),
394 - $x->atom("STRING"), 0, 1000, 0);
395 + eval { ($window_name) = $x->GetProperty($named_window_id, $x->atom("WM_NAME"),
396 + $x->atom("STRING"), 0, 1000, 0); };
397 + $window_name = "?" if $@;
398 last if defined($window_name) && $window_name ne "";
399 (undef, $named_window_id) = $x->QueryTree($named_window_id);
400 if (!defined($named_window_id)) {