Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.desktop parser doesn't safely handle malformed files #15

Closed
kode54 opened this issue Mar 26, 2024 · 1 comment
Closed

.desktop parser doesn't safely handle malformed files #15

kode54 opened this issue Mar 26, 2024 · 1 comment

Comments

@kode54
Copy link

kode54 commented Mar 26, 2024

There are several issues with this parser's naïve .desktop parser:

  • If the file doesn't contain a [Desktop Entry] section header, an empty app struct is returned
  • If any fields are missing, even if they're necessary for parsing, they're simply left as NULL pointers

There is at least a crash in compare_app_name in either of those cases, if both the name_localized and name fields of any .desktop file are left uninitialized after the struct is calloc'd. Any others may also result in different crashes elsewhere.

I'm not sure which fields are absolutely mandatory for the menu generator to function, so I'll leave it up to someone familiar with the rest of the code to add the necessary validation.

At the very least, all mandatory headers should be checked for presence after parsing the .desktop file, then the app struct should be cleaned up and a NULL returned if the .desktop turns out to be invalid.

The example in my case, somehow, the Arch User Repository package gqrx-nrsc5-git installs an invalid .desktop file in /usr/share/applications, which contains only the following line and nothing more:

StartupNotify=false

(Incidentally, this was caught by a PKGBUILD not being updated past the point of the upstream .desktop file being renamed, which causes it to append a string to a non-existent file and install that in the package.)

@Consolatis
Copy link
Member

Consolatis commented Mar 26, 2024

We should really get the CI going with the test framework and also add an invalid .desktop file like that above to the tests.

johanmalm added a commit that referenced this issue Mar 26, 2024
Handle null pointers in compare_app_name().

Do not create an entry unless a file contains a `[Desktop Entry]`
section and a `Name=` field.

Reported-by: @kode54

Fixes: #15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants