Merge lp:~jpakkane/thumbnailer/validate-appid into lp:thumbnailer

Proposed by Jussi Pakkanen
Status: Rejected
Rejected by: Michi Henning
Proposed branch: lp:~jpakkane/thumbnailer/validate-appid
Merge into: lp:thumbnailer
Diff against target: 53 lines (+15/-8)
2 files modified
debian/control (+1/-0)
src/thumbnailcache.cpp (+14/-8)
To merge this branch: bzr merge lp:~jpakkane/thumbnailer/validate-appid
Reviewer Review Type Date Requested Status
Michi Henning (community) Disapprove
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+219838@code.launchpad.net

Commit message

Validate appid with a regex.

Description of the change

Validate appid with a regex.

We have to be a bit careful with this, because it requires G++ 4.9's regex support and trusty does not have it.

To post a comment you must log in.
85. By Jussi Pakkanen

Minor cleanup.

86. By Jussi Pakkanen

Even better.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

No longer applies.

review: Disapprove

Unmerged revisions

86. By Jussi Pakkanen

Even better.

85. By Jussi Pakkanen

Minor cleanup.

84. By Jussi Pakkanen

Validate app name with a regex.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-04-01 10:58:16 +0000
3+++ debian/control 2014-05-16 13:26:13 +0000
4@@ -4,6 +4,7 @@
5 Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
6 Standards-Version: 3.9.4
7 Build-Depends: cmake,
8+ g++ (>= 4.9),
9 debhelper (>= 9),
10 gstreamer1.0-plugins-good,
11 libexif-dev,
12
13=== modified file 'src/thumbnailcache.cpp'
14--- src/thumbnailcache.cpp 2014-02-20 16:39:51 +0000
15+++ src/thumbnailcache.cpp 2014-05-16 13:26:13 +0000
16@@ -35,6 +35,7 @@
17 #include<vector>
18 #include<algorithm>
19 #include<dirent.h>
20+#include<regex>
21
22 using namespace std;
23
24@@ -106,16 +107,21 @@
25 if(numread == 0) {
26 throw runtime_error("Could not read from /proc/self/attr/current.");
27 }
28+ // Output may or may not end in a newline.
29+ if(data[numread-1] == '\n') {
30+ numread--;
31+ }
32 data[numread] = '\0';
33 string core(data);
34- string::size_type ind = core.find('_');
35- if(ind == string::npos) {
36- throw runtime_error("/proc/self/attr/current malformed, does not have _ in it.");
37- }
38- if(ind == 0) {
39- throw runtime_error("/proc/self/attr/current malformed, starts with '_'.");
40- }
41- return core.substr(0, ind);
42+ regex re(R"(([a-z0-9][a-z0-9+.-]+)_[a-zA-Z0-9+.-]+_[0-9][a-zA-Z0-9.+:~-]*)");
43+ smatch base_match;
44+ // Match only returns true if entire input string matched.
45+ if(!regex_match(core, base_match, re)) {
46+ string m("Invalid ApplicationID: ");
47+ m += core + ".";
48+ throw runtime_error(m);
49+ }
50+ return base_match[1].str();
51 }
52
53 class ThumbnailCachePrivate {

Subscribers

People subscribed via source and target branches

to all changes: