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
=== modified file 'src/modules/application/application_manager.cc'
--- src/modules/application/application_manager.cc 2013-07-25 13:01:28 +0000
+++ src/modules/application/application_manager.cc 2013-07-25 13:01:28 +0000
@@ -181,12 +181,12 @@
181 this, desktopFile.toLatin1().data());181 this, desktopFile.toLatin1().data());
182 DASSERT(desktopFile != NULL);182 DASSERT(desktopFile != NULL);
183 const struct { const char* const name; int size; unsigned int flag; } kEntryNames[] = {183 const struct { const char* const name; int size; unsigned int flag; } kEntryNames[] = {
184 { "Name=", sizeof("Name=") - 1, 1 << DesktopData::kNameIndex },184 { "Name", sizeof("Name") - 1, 1 << DesktopData::kNameIndex },
185 { "Comment=", sizeof("Comment=") - 1, 1 << DesktopData::kCommentIndex },185 { "Comment", sizeof("Comment") - 1, 1 << DesktopData::kCommentIndex },
186 { "Icon=", sizeof("Icon=") - 1, 1 << DesktopData::kIconIndex },186 { "Icon", sizeof("Icon") - 1, 1 << DesktopData::kIconIndex },
187 { "Exec=", sizeof("Exec=") - 1, 1 << DesktopData::kExecIndex },187 { "Exec", sizeof("Exec") - 1, 1 << DesktopData::kExecIndex },
188 { "Path=", sizeof("Path=") - 1, 1 << DesktopData::kPathIndex },188 { "Path", sizeof("Path") - 1, 1 << DesktopData::kPathIndex },
189 { "X-Ubuntu-StageHint=", sizeof("X-Ubuntu-StageHint=") - 1, 1 << DesktopData::kStageHintIndex }189 { "X-Ubuntu-StageHint", sizeof("X-Ubuntu-StageHint") - 1, 1 << DesktopData::kStageHintIndex }
190 };190 };
191 const unsigned int kAllEntriesMask =191 const unsigned int kAllEntriesMask =
192 (1 << DesktopData::kNameIndex) | (1 << DesktopData::kCommentIndex)192 (1 << DesktopData::kNameIndex) | (1 << DesktopData::kCommentIndex)
@@ -207,11 +207,9 @@
207 }207 }
208208
209 // Validate "magic key" (standard group header).209 // Validate "magic key" (standard group header).
210 if (file.readLine(buffer, kBufferSize) != -1) {210 while (file.readLine(buffer, kBufferSize) != -1) {
211 if (strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]" - 1))) {211 if (!strncmp(buffer, "[Desktop Entry]", sizeof("[Desktop Entry]" - 1)))
212 DLOG("not a desktop file");212 break;
213 return false;
214 }
215 }213 }
216214
217 int length;215 int length;
@@ -224,17 +222,50 @@
224 DLOG("reached next group header, leaving loop");222 DLOG("reached next group header, leaving loop");
225 break;223 break;
226 }224 }
225 bool validLine = true;
227 // Lookup entries ignoring duplicates if any.226 // Lookup entries ignoring duplicates if any.
228 for (int i = 0; i < kEntriesCount; i++) {227 for (int i = 0; i < kEntriesCount; i++) {
229 if (!strncmp(buffer, kEntryNames[i].name, kEntryNames[i].size)) {228 if (!strncmp(buffer, kEntryNames[i].name, kEntryNames[i].size)) {
230 if (~entryFlags & kEntryNames[i].flag) {229 if (~entryFlags & kEntryNames[i].flag) {
230 int keyLength = kEntryNames[i].size;
231 buffer[length-1] = '\0';231 buffer[length-1] = '\0';
232 entries_[i] = QString::fromLatin1(&buffer[kEntryNames[i].size]);232
233 if (length == keyLength + 1) {
234 validLine = false;
235 break;
236 }
237
238 if ((const char)buffer[keyLength] != ' ' && (const char)buffer[keyLength] != '=') {
239 // Skip, not the key we're looking for.
240 continue;
241 }
242
243 bool gotEqual = false;
244 while(keyLength < length) {
245 if ((const char)buffer[keyLength] == ' ') {
246 // Ignore spaces.
247 } else if ((const char)buffer[keyLength] == '=') {
248 gotEqual = true;
249 } else {
250 break;
251 }
252 keyLength++;
253 }
254 if (!gotEqual) {
255 validLine = false;
256 break;
257 }
258 entries_[i] = QString::fromLatin1(&buffer[keyLength]);
233 entryFlags |= kEntryNames[i].flag;259 entryFlags |= kEntryNames[i].flag;
260 DLOG("Found entry for %s: %s", kEntryNames[i].name, entries_[i].toLatin1().data());
234 break;261 break;
235 }262 }
236 }263 }
237 }264 }
265 if (!validLine) {
266 DLOG("Malformed .desktop file entry, ignoring: %s", buffer);
267 continue;
268 }
238 // Stop when matching the right number of entries.269 // Stop when matching the right number of entries.
239 if (entryFlags == kAllEntriesMask) {270 if (entryFlags == kAllEntriesMask) {
240 break;271 break;

Subscribers

People subscribed via source and target branches