Merge lp:~saviq/qtubuntu/more-robust-desktop-parsing into lp:qtubuntu

Proposed by Michał Sawicz
Status: Rejected
Rejected by: Gerry Boland
Proposed branch: lp:~saviq/qtubuntu/more-robust-desktop-parsing
Merge into: lp:qtubuntu
Prerequisite: lp:~saviq/qtubuntu/respect-path
Diff against target: 89 lines (+43/-12)
1 file modified
src/modules/application/application_manager.cc (+43/-12)
To merge this branch: bzr merge lp:~saviq/qtubuntu/more-robust-desktop-parsing
Reviewer Review Type Date Requested Status
Gerry Boland (community) Disapprove
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+176931@code.launchpad.net

This proposal supersedes a proposal from 2013-07-25.

Commit message

Make desktop file parsing more robust.

Ignore spaces around "=" and error out on malformed lines.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
http://jenkins.qa.ubuntu.com/job/qtubuntu-autolanding/41/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/qtubuntu-trusty-armhf-autolanding/2/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

SurfaceFlinger support dropped, so this MR invalid

review: Disapprove

Unmerged revisions

158. By Michał Sawicz

Also skip if just the key was provided.

157. By Michał Sawicz

Ignore spaces around "=" in .desktop files.

156. By Michał Sawicz

Scan for a [Desktop Entry] group, don't assume it's on the first line.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/application/application_manager.cc'
2--- src/modules/application/application_manager.cc 2013-07-25 13:01:28 +0000
3+++ src/modules/application/application_manager.cc 2013-07-25 13:01:28 +0000
4@@ -181,12 +181,12 @@
5 this, desktopFile.toLatin1().data());
6 DASSERT(desktopFile != NULL);
7 const struct { const char* const name; int size; unsigned int flag; } kEntryNames[] = {
8- { "Name=", sizeof("Name=") - 1, 1 << DesktopData::kNameIndex },
9- { "Comment=", sizeof("Comment=") - 1, 1 << DesktopData::kCommentIndex },
10- { "Icon=", sizeof("Icon=") - 1, 1 << DesktopData::kIconIndex },
11- { "Exec=", sizeof("Exec=") - 1, 1 << DesktopData::kExecIndex },
12- { "Path=", sizeof("Path=") - 1, 1 << DesktopData::kPathIndex },
13- { "X-Ubuntu-StageHint=", sizeof("X-Ubuntu-StageHint=") - 1, 1 << DesktopData::kStageHintIndex }
14+ { "Name", sizeof("Name") - 1, 1 << DesktopData::kNameIndex },
15+ { "Comment", sizeof("Comment") - 1, 1 << DesktopData::kCommentIndex },
16+ { "Icon", sizeof("Icon") - 1, 1 << DesktopData::kIconIndex },
17+ { "Exec", sizeof("Exec") - 1, 1 << DesktopData::kExecIndex },
18+ { "Path", sizeof("Path") - 1, 1 << DesktopData::kPathIndex },
19+ { "X-Ubuntu-StageHint", sizeof("X-Ubuntu-StageHint") - 1, 1 << DesktopData::kStageHintIndex }
20 };
21 const unsigned int kAllEntriesMask =
22 (1 << DesktopData::kNameIndex) | (1 << DesktopData::kCommentIndex)
23@@ -207,11 +207,9 @@
24 }
25
26 // Validate "magic key" (standard group header).
27- if (file.readLine(buffer, kBufferSize) != -1) {
28- if (strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]" - 1))) {
29- DLOG("not a desktop file");
30- return false;
31- }
32+ while (file.readLine(buffer, kBufferSize) != -1) {
33+ if (!strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]" - 1)))
34+ break;
35 }
36
37 int length;
38@@ -224,17 +222,50 @@
39 DLOG("reached next group header, leaving loop");
40 break;
41 }
42+ bool validLine = true;
43 // Lookup entries ignoring duplicates if any.
44 for (int i = 0; i < kEntriesCount; i++) {
45 if (!strncmp(buffer, kEntryNames[i].name, kEntryNames[i].size)) {
46 if (~entryFlags & kEntryNames[i].flag) {
47+ int keyLength = kEntryNames[i].size;
48 buffer[length-1] = '\0';
49- entries_[i] = QString::fromLatin1(&buffer[kEntryNames[i].size]);
50+
51+ if (length == keyLength + 1) {
52+ validLine = false;
53+ break;
54+ }
55+
56+ if ((const char)buffer[keyLength] != ' ' && (const char)buffer[keyLength] != '=') {
57+ // Skip, not the key we're looking for.
58+ continue;
59+ }
60+
61+ bool gotEqual = false;
62+ while(keyLength < length) {
63+ if ((const char)buffer[keyLength] == ' ') {
64+ // Ignore spaces.
65+ } else if ((const char)buffer[keyLength] == '=') {
66+ gotEqual = true;
67+ } else {
68+ break;
69+ }
70+ keyLength++;
71+ }
72+ if (!gotEqual) {
73+ validLine = false;
74+ break;
75+ }
76+ entries_[i] = QString::fromLatin1(&buffer[keyLength]);
77 entryFlags |= kEntryNames[i].flag;
78+ DLOG("Found entry for %s: %s", kEntryNames[i].name, entries_[i].toLatin1().data());
79 break;
80 }
81 }
82 }
83+ if (!validLine) {
84+ DLOG("Malformed .desktop file entry, ignoring: %s", buffer);
85+ continue;
86+ }
87 // Stop when matching the right number of entries.
88 if (entryFlags == kAllEntriesMask) {
89 break;

Subscribers

People subscribed via source and target branches