xdg-desktop-menu uninstall hangs if menu file names have spaces

Bug #1432932 reported by Mark Malakanov
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Xdg-utils
Fix Released
Medium
xdg-utils (Ubuntu)
Fix Released
High
Unassigned

Bug Description

xdg-desktop-menu uninstall hangs if menu file names have spaces
for example when uninstalling a custom menu it hangs on processing "$HOME/.config/menus/applications-merged/wine-Programs-Tina 9 - TI-Component Help.menu" file.

Tags: patch
Revision history for this message
In , Mgiuca-n (mgiuca-n) wrote :

Steps to reproduce:

1. Create a .desktop file with a vendor prefix and a space in the name. e.g., "foo-bar baz.desktop".
2. Run: xdg-desktop-menu install --mode user "foo-bar baz.desktop"

Expected result: The file is copied to "~/.local/share/applications/foo-bar baz.desktop".

Actual result:
xdg-desktop-menu: filename 'baz.desktop' does not have a proper vendor prefix
A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
with a dash ("-"). An example filename is 'example-baz.desktop'
Use --novendor to override or 'xdg-desktop-menu --manual' for additional info.

This is because it thinks I am passing two separate filenames ("foo-bar" and "baz.desktop") even though I correctly used quotes on the command line. This is caused by line 998 of the script, which concatenates all arguments ending in .desktop onto $desktop_files, separating each argument with a space. After that point, it is impossible to tell which spaces separate arguments and which are part of the filename.

(Note that if all of the space-separated parts of the filename contain a "-", you don't see the above error, it just fails silently because it can't find the files it is trying to copy.)

Revision history for this message
In , Martin von Gagern (gagern) wrote :

Line 895 of the xdg-desktop-menu script passed a file name unquoted to grep:

http://cgit.freedesktop.org/xdg/xdg-utils/tree/scripts/xdg-desktop-menu?id=2baf6ae56f9b622ca51aa79ff370676aaef93908#n895

if grep 'generated and managed by xdg-desktop-menu' $menu_file > /dev/null 2> /dev/null; then

On my system I have a file name containing the sequence ' - ', which caused grep to read from stdin, with obscure side effects. I believe that the command should be something like this:

grep 'ge…nu' -- "$menu_file"

Revision history for this message
In , Rdieter-math (rdieter-math) wrote :

Since the "-" character is treated as special by
http://standards.freedesktop.org/menu-spec/menu-spec-latest.html

I'd highly recommend .desktop files use it only to specify vendor as referenced in the spec above. Doing otherwise is just asking for trouble.

(While researching this more, there are many occurances of unquoted file access... fixing this potential problem fully will take some care).

Revision history for this message
In , Rdieter-math (rdieter-math) wrote :

Fixing this could get a little ugly... in the meantime I would simply and strongly recommend avoiding the use of .desktop filenames with spaces (converting " " to "_" or something...)

Revision history for this message
In , Rdieter-math (rdieter-math) wrote :
Revision history for this message
In , Martin von Gagern (gagern) wrote :

The desktop files in question were installed by Wine. They had the format
"wine-Programs-WindowsVendor-WindowsAppName.desktop"
i.e. "wine-" as vendor prefix, and then the directory structure inside the start menu encoded using "-" as structure separator. The way I read the spec you mentioned, that only specifies the part up to the first "-", i.e. "wine-". I can see no restriction on the part after that, although I might well have missed that.

In any case, even though I only had two instances of " - " inside desktop files, I had a not more containing spaces, so xdg-desktop-menu should be able to cope with these. Handling that single location is therefore a step in the right direction. Thanks for fixing this.

Revision history for this message
Mark Malakanov (mark-malakanov) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in xdg-utils (Ubuntu):
status: New → Confirmed
Revision history for this message
In , MestreLion (mestrelion) wrote :

This affects more than just installing `.desktop` files. It also affects uninstalling *any* .directory file, with spaces or not, if `XDG_CONFIG_HOME/menus/applications-merged` contains a `.menu` file with spaces.

In this case, a simple `xdg-desktop-menu uninstall vendor-foo.directory vendor-bar.desktop` *freezes*. Notice there's no spaces in those names!

This was reported in Ubuntu as https://bugs.launchpad.net/xdg-utils/+bug/1432932 , and it contains a working patch that does not seem ugly: it simply quotes the vars as they should be.

"avoiding the use of .desktop filenames with spaces" is not always an option: wine creates such files, and they do so by design (its .menu files are named after their windows `.lnk` counterparts).

So if a user has wine-installed games, no other software will be able to uninstall its own .directory files!

Any chance this patch could be merged?

Changed in xdg-utils:
importance: Unknown → Medium
status: Unknown → Confirmed
MestreLion (mestrelion)
no longer affects: xdg-utils
Changed in xdg-utils:
importance: Unknown → Medium
status: Unknown → Fix Released
Revision history for this message
Sebastien Bacher (seb128) wrote :
Changed in xdg-utils (Ubuntu):
importance: Undecided → High
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Patches

Remote bug watches

Bug watches keep track of this bug in other bug trackers.