<html>
<head>
<base href="https://bugs.freedesktop.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - xdg-open does not handle x-schemes with no URL correctly (suggested PATCH)"
href="https://bugs.freedesktop.org/show_bug.cgi?id=86340">86340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>xdg-open does not handle x-schemes with no URL correctly (suggested PATCH)
</td>
</tr>
<tr>
<th>Product</th>
<td>Portland
</td>
</tr>
<tr>
<th>Version</th>
<td>1.1.0 rc2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux (All)
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Component</th>
<td>xdg-utils
</td>
</tr>
<tr>
<th>Assignee</th>
<td>portland-bugs@lists.freedesktop.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>infinite.craziness@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>I want tp use xdg-open to open my default browser or email-client by doing e.g.
xdg-open http: or xdg-open mailto:
If I do that, (in the former case) it opens the browser an empty page with the
http:// URL and the error 'Page not found' (of course)
Here follows the fix, it needed some fixing on argument quoting (since of the
arg is empty, it must not be quoted at all). I took the opportunity to fix <a class="bz_bug_link
bz_status_NEW "
title="NEW - xdg-open: command injection vulnerability"
href="show_bug.cgi?id=66670">bug
66670</a> and change the quoting around the user's argument to single rather than
double (it also takes care of single quotes present in it).
Also, first_word was defined twice (once in the beginning and once later one
along with last_word) - moved definition of both to the beginning
And lastly, binary_to_desktop_file handled the deprecated applnk location, but
nowhere else in the script was this supported - added it to all the other
functions
--- xdg-open 2014-11-16 12:14:06.587351388 +0200
+++ xdg-open.fix 2014-11-16 13:08:47.224959973 +0200
@@ -132,6 +132,12 @@
echo "$first"
}
+last_word()
+{
+ read first rest
+ echo "$rest"
+}
+
#-------------------------------------------------------------
# map a binary to a .desktop file
binary_to_desktop_file()
@@ -172,14 +178,16 @@
IFS=:
for dir in $search; do
unset IFS
- [ "$dir" ] && [ -d "$dir/applications" ] || continue
- file="$dir/applications/$desktop"
- [ -r "$file" ] || continue
- # Remove any arguments (%F, %f, %U, %u, etc.).
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`"
- command="`which "$command"`"
- readlink -f "$command"
- return
+ [ "$dir" ] || continue
+ [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
+ for file in "$dir"/applications/*.desktop
"$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop
"$dir"/applnk/*/*.desktop; do
+ [ -r "$file" ] || continue
+ # Remove any arguments (%F, %f, %U, %u, etc.).
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`"
+ command="`which "$command"`"
+ readlink -f "$command"
+ return
+ done
done
}
@@ -454,19 +462,6 @@
return 0
}
-# This handles backslashes but not quote marks.
-first_word()
-{
- read first rest
- echo "$first"
-}
-
-last_word()
-{
- read first rest
- echo "$rest"
-}
-
open_darwin()
{
open "$1"
@@ -572,10 +567,12 @@
command_exec=`which $command 2>/dev/null`
arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
last_word`"
arg_one="`echo "$arg" | sed 's/[&*\\]/\\\\&/g'`"
- arguments_exec="`echo "$arguments" | sed -e
's*%[fFuU]*"'"$arg_one"'"*g'`"
+ arg_one="`echo "$arg" | sed \"s/'/'\\\"'\\\"'/g\"`"
+ [ -n "$arg_one" ] && arg_one="'$arg_one'"
+ arguments_exec="`echo "$arguments" | sed -e 's*%[fFuU]*'"$arg_one"'*g'`"
if [ -x "$command_exec" ] ; then
- if echo "$arguments" | grep -iq '%[fFuU]' ; then
+ if echo "$arguments" | grep -iq '%[fu]' ; then
echo START "$command_exec" "$arguments_exec"
eval "$command_exec" "$arguments_exec"
else
@@ -600,15 +597,13 @@
filetype="$2"
default=`xdg-mime query default "$filetype"`
if [ -n "$default" ] ; then
- xdg_user_dir="$XDG_DATA_HOME"
- [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
-
- xdg_system_dirs="$XDG_DATA_DIRS"
- [ -n "$xdg_system_dirs" ] ||
xdg_system_dirs=/usr/local/share/:/usr/share/
+ [ -n "$XDG_DATA_HOME" ] && xdg_user_dir="$XDG_DATA_HOME" ||
xdg_user_dir="$HOME/.local/share"
+ [ -n "$XDG_DATA_DIRS" ] && xdg_system_dirs="$XDG_DATA_DIRS" ||
xdg_system_dirs=/usr/local/share/:/usr/share/
DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
- search_desktop_file "$default" "$x/applications/" "$1"
+ [ -d "$x/applications/" ] && search_desktop_file "$default"
"$x/applications/" "$1"
+ [ -d "$x/applnk/" ] && search_desktop_file "$default" "$x/applnk/"
"$1"
done
fi
}
@@ -622,9 +617,11 @@
open_generic_xdg_x_scheme_handler()
{
scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
+ uri="`echo $1 | sed -n 's/^[[:alnum:]+\.-]*:\/\{1,\}//p'`"
if [ -n $scheme ]; then
filetype="x-scheme-handler/$scheme"
- open_generic_xdg_mime "$1" "$filetype"
+ [ -n "$uri" ] && open_generic_xdg_mime "$1" "$filetype"
+ open_generic_xdg_mime "" "$filetype"
fi
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>