Merge lp:~mhr3/libunity/fix-1063300-6.0 into lp:libunity/6.0

Proposed by Michal Hruby
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: 186
Merged at revision: 186
Proposed branch: lp:~mhr3/libunity/fix-1063300-6.0
Merge into: lp:libunity/6.0
Diff against target: 346 lines (+94/-35)
3 files modified
protocol/protocol-lens-interface.vala (+12/-3)
src/unity-lens-private.vala (+15/-7)
test/vala/test-lens.vala (+67/-25)
To merge this branch: bzr merge lp:~mhr3/libunity/fix-1063300-6.0
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Review via email: mp+130042@code.launchpad.net

Commit message

Fix possible crash when splitting uris

Description of the change

Fix possible crash when splitting uris

UNBLOCK

To post a comment you must log in.
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'protocol/protocol-lens-interface.vala'
2--- protocol/protocol-lens-interface.vala 2012-09-04 11:40:42 +0000
3+++ protocol/protocol-lens-interface.vala 2012-10-17 08:16:32 +0000
4@@ -38,6 +38,15 @@
5 public HashTable<string, Variant> hints;
6 }
7
8+/* The error types that can be thrown from DBus methods */
9+[DBus (name = "com.canonical.Unity.LensError")]
10+public errordomain LensError
11+{
12+ FAILED,
13+ INVALID_SCOPE
14+}
15+
16+
17 public enum HandledType
18 {
19 NOT_HANDLED,
20@@ -74,12 +83,12 @@
21
22 // FIXME: should have the hints param and activate_with_hints should go away
23 public async abstract ActivationReplyRaw activate (
24- string uri, uint action_type) throws IOError;
25+ string uri, uint action_type) throws IOError, LensError;
26
27 public async abstract ActivationReplyRaw activate_with_hints (
28- string uri, uint action_type, HashTable<string, Variant> hints) throws IOError;
29+ string uri, uint action_type, HashTable<string, Variant> hints) throws IOError, LensError;
30
31- public async abstract HashTable<string, Variant> update_preview_property (string uri, HashTable<string, Variant> values) throws IOError;
32+ public async abstract HashTable<string, Variant> update_preview_property (string uri, HashTable<string, Variant> values) throws IOError, LensError;
33
34 public async abstract HashTable<string, Variant> search (
35 string search_string, HashTable<string, Variant> hints) throws IOError;
36
37=== modified file 'src/unity-lens-private.vala'
38--- src/unity-lens-private.vala 2012-09-04 11:40:42 +0000
39+++ src/unity-lens-private.vala 2012-10-17 08:16:32 +0000
40@@ -493,8 +493,8 @@
41 queue_info_changed ();
42 }
43
44- public async ActivationReplyRaw activate (string uri,
45- uint action_type) throws IOError
46+ public async ActivationReplyRaw activate (
47+ string uri, uint action_type) throws IOError, LensError
48 {
49 var hints = new HashTable<string, Variant> (null, null);
50 var reply = yield activate_with_hints (uri, action_type, hints);
51@@ -503,7 +503,7 @@
52
53 public async ActivationReplyRaw activate_with_hints (
54 string uri, uint action_type,
55- HashTable<string, Variant> hints) throws IOError
56+ HashTable<string, Variant> hints) throws IOError, LensError
57 {
58 string[] tokens;
59 ScopeProxy? scope = null;
60@@ -513,11 +513,15 @@
61 {
62 case ActionType.PREVIEW_ACTION:
63 tokens = uri.split (":", 3);
64+ if (tokens.length < 3)
65+ throw new LensError.FAILED ("Malformatted URI parameter");
66 scope = get_scope_for_uid (tokens[1]);
67 scope_uri = "%s:%s".printf (tokens[0], tokens[2]);
68 break;
69 default:
70 tokens = uri.split (":", 2);
71+ if (tokens.length < 2)
72+ throw new LensError.FAILED ("Malformatted URI parameter");
73 scope = get_scope_for_uid (tokens[0]);
74 scope_uri = tokens[1];
75 break;
76@@ -535,7 +539,7 @@
77 else
78 {
79 warning ("Unable to find scope for activation request: %s", uri);
80- raw.uri = uri;
81+ throw new LensError.INVALID_SCOPE ("Invalid URI parameter");
82 }
83
84 // FIXME: do we need to mangle uris/actions that the scope provided?
85@@ -546,11 +550,14 @@
86 return raw;
87 }
88
89- public async HashTable<string, Variant> update_preview_property (string uri,
90- HashTable<string, Variant> values) throws IOError
91+ public async HashTable<string, Variant> update_preview_property (
92+ string uri, HashTable<string, Variant> values) throws IOError, LensError
93 {
94 string[] tokens = uri.split (":", 2);
95- string? scope_uri = tokens[1];
96+ if (tokens.length < 2)
97+ throw new LensError.FAILED ("Malformatted URI parameter");
98+
99+ string scope_uri = tokens[1];
100 ScopeProxy? scope = get_scope_for_uid (tokens[0]);
101
102 if (scope is ScopeProxy)
103@@ -561,6 +568,7 @@
104 else
105 {
106 warning ("Unable to find scope for activation request: %s", uri);
107+ throw new LensError.INVALID_SCOPE ("Invalid URI parameter");
108 }
109
110 return new HashTable<string, Variant> (str_hash, str_equal);
111
112=== modified file 'test/vala/test-lens.vala'
113--- test/vala/test-lens.vala 2012-10-02 16:16:29 +0000
114+++ test/vala/test-lens.vala 2012-10-17 08:16:32 +0000
115@@ -54,6 +54,7 @@
116 Test.add_data_func ("/Unit/Lens/ReplyHint", test_lens_reply_hint);
117 Test.add_data_func ("/Unit/Lens/Sources", test_lens_sources);
118 Test.add_data_func ("/Unit/Lens/Activation", test_lens_activation);
119+ Test.add_data_func ("/Unit/Lens/InvalidActivation", test_lens_invalid_activation);
120 Test.add_data_func ("/Unit/Lens/Preview", test_lens_preview);
121 Test.add_data_func ("/Unit/Lens/Preview/Async", test_lens_preview_async);
122 Test.add_data_func ("/Unit/Lens/Preview/AsyncWithNull", test_lens_preview_async_with_null);
123@@ -163,9 +164,10 @@
124 assert (scope_up == true);
125 }
126
127- private static void call_lens_method (string method_name,
128+ private static void call_lens_method (string method_name,
129 Variant? parameters,
130- Func<Variant?>? cb)
131+ Func<Variant?>? cb,
132+ Func<Error?>? error_cb = null)
133 {
134 DBusConnection? bus = null;
135 try
136@@ -190,35 +192,43 @@
137 var reply = bus.call.end (res);
138 if (cb != null) cb (reply);
139 }
140- catch (Error e)
141+ catch (Error err)
142 {
143- warning ("%s", e.message);
144+ if (error_cb != null)
145+ error_cb (err);
146+ else
147+ warning ("%s", err.message);
148 }
149 });
150 }
151
152 private static void call_lens_search (string search_string,
153- Func<Variant?>? cb = null)
154+ Func<Variant?>? cb = null,
155+ Func<Error?>? error_cb = null)
156 {
157 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));
158 vb.add ("s", search_string);
159 vb.open (new VariantType ("a{sv}"));
160 vb.close ();
161
162- call_lens_method ("Search", vb.end (), cb);
163+ call_lens_method ("Search", vb.end (), cb, error_cb);
164 }
165
166- private static void call_lens_activate (string uri, uint action_type,
167- Func<Variant?>? cb = null)
168+ private static void call_lens_activate (string uri,
169+ Unity.Protocol.ActionType action_type,
170+ Func<Variant?>? cb = null,
171+ Func<Error?>? error_cb = null)
172 {
173 call_lens_activate_with_hints (uri, action_type,
174 new HashTable<string, Variant> (null, null),
175- cb);
176+ cb, error_cb);
177 }
178
179 private static void call_lens_activate_with_hints (
180- string uri, uint action_type, HashTable<string, Variant> hints,
181- Func<Variant?>? cb = null)
182+ string uri, Unity.Protocol.ActionType action_type,
183+ HashTable<string, Variant> hints,
184+ Func<Variant?>? cb = null,
185+ Func<Error?>? error_cb = null)
186 {
187 Variant parameters;
188 // let's make sure we test both variants, since we have to support them
189@@ -227,24 +237,25 @@
190 Variant ht = hints;
191 parameters = new Variant ("(su@a{sv})", uri, action_type, ht);
192
193- call_lens_method ("ActivateWithHints", parameters, cb);
194+ call_lens_method ("ActivateWithHints", parameters, cb, error_cb);
195 }
196 else
197 {
198 parameters = new Variant ("(su)", uri, action_type);
199
200- call_lens_method ("Activate", parameters, cb);
201+ call_lens_method ("Activate", parameters, cb, error_cb);
202 }
203 }
204
205 private static void call_lens_update_preview_property (string uri, HashTable<string, Variant> props,
206- Func<Variant?>? cb = null)
207+ Func<Variant?>? cb = null,
208+ Func<Error?>? error_cb = null)
209 {
210 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));
211 vb.add ("s", uri);
212 vb.add_value (props);
213
214- call_lens_method ("UpdatePreviewProperty", vb.end(), cb);
215+ call_lens_method ("UpdatePreviewProperty", vb.end(), cb, error_cb);
216 }
217
218 public static void test_lens_search ()
219@@ -747,7 +758,8 @@
220 }));
221
222 ml = new MainLoop ();
223- call_lens_activate (mangled_uri, 0, () =>
224+ var action = Unity.Protocol.ActionType.ACTIVATE_RESULT;
225+ call_lens_activate (mangled_uri, action, () =>
226 {
227 ml.quit ();
228 });
229@@ -756,6 +768,28 @@
230 assert (got_activate_uri_signal);
231 }
232
233+ public static void test_lens_invalid_activation ()
234+ {
235+ // ignore warnings
236+ Test.log_set_fatal_handler (() => { return false; });
237+ Unity.Protocol.ActionType action;
238+ var ml = new MainLoop ();
239+
240+ Func<Error?> err_cb = (err) =>
241+ {
242+ assert (err is Unity.Protocol.LensError);
243+ ml.quit ();
244+ };
245+ action = Unity.Protocol.ActionType.ACTIVATE_RESULT;
246+ call_lens_activate ("", action, null, err_cb);
247+ assert (run_with_timeout (ml, 5000));
248+
249+ ml = new MainLoop ();
250+ action = Unity.Protocol.ActionType.PREVIEW_RESULT;
251+ call_lens_activate (":", action, null, err_cb);
252+ assert (run_with_timeout (ml, 5000));
253+ }
254+
255 public static void test_lens_preview ()
256 {
257 SignalWrapper[] signals = null;
258@@ -792,7 +826,8 @@
259
260 ml = new MainLoop ();
261 Unity.Protocol.Preview? reconstructed = null;
262- call_lens_activate (mangled_uri, 1, (reply) =>
263+ var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
264+ call_lens_activate (mangled_uri, action_type, (reply) =>
265 {
266 var v = reply.get_child_value (0);
267 Unity.Protocol.ActivationReplyRaw reply_struct =
268@@ -816,7 +851,9 @@
269
270 // expecting button_id:scope_uid:uri
271 ml = new MainLoop ();
272- call_lens_activate ("%s:%s".printf (action.id, mangled_uri), 2, (reply) =>
273+ action_type = Unity.Protocol.ActionType.PREVIEW_ACTION;
274+ var activate_uri = "%s:%s".printf (action.id, mangled_uri);
275+ call_lens_activate (activate_uri, action_type, (reply) =>
276 {
277 ml.quit ();
278 });
279@@ -871,7 +908,8 @@
280
281 ml = new MainLoop ();
282 Unity.Protocol.Preview? reconstructed = null;
283- call_lens_activate (mangled_uri, 1, (reply) =>
284+ var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
285+ call_lens_activate (mangled_uri, action_type, (reply) =>
286 {
287 var v = reply.get_child_value (0);
288 Unity.Protocol.ActivationReplyRaw reply_struct =
289@@ -897,7 +935,9 @@
290
291 // expecting button_id:scope_uid:uri
292 ml = new MainLoop ();
293- call_lens_activate ("%s:%s".printf (action.id, mangled_uri), 2, (reply) =>
294+ action_type = Unity.Protocol.ActionType.PREVIEW_ACTION;
295+ var activate_uri = "%s:%s".printf (action.id, mangled_uri);
296+ call_lens_activate (activate_uri, action_type, (reply) =>
297 {
298 ml.quit ();
299 });
300@@ -945,7 +985,8 @@
301
302 ml = new MainLoop ();
303 Unity.Protocol.Preview? reconstructed = null;
304- call_lens_activate (mangled_uri, 1, (reply) =>
305+ var action = Unity.Protocol.ActionType.PREVIEW_RESULT;
306+ call_lens_activate (mangled_uri, action, (reply) =>
307 {
308 var v = reply.get_child_value (0);
309 Unity.Protocol.ActivationReplyRaw reply_struct =
310@@ -979,7 +1020,6 @@
311 bool got_preview_uri_signal = false;
312 string? request_item_signal_uri = null;
313 int request_item_signal_count = 0;
314- Unity.PreviewAction? action = null;
315
316 signals += new SignalWrapper (local_scope,
317 local_scope.activate_uri.connect ((uri) =>
318@@ -1113,7 +1153,8 @@
319 var mangled_uri = lens_results_model.get_string (iter, 0);
320
321 Unity.Protocol.GenericPreview? reconstructed = null;
322- call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>
323+ var action = Unity.Protocol.ActionType.PREVIEW_RESULT;
324+ call_lens_activate (mangled_uri, action, (reply) =>
325 {
326 var v = reply.get_child_value (0);
327 Unity.Protocol.ActivationReplyRaw reply_struct =
328@@ -1167,7 +1208,7 @@
329 {
330 got_activated_signal = true;
331 assert (action.hints["passing-extra-info"].get_boolean () == true);
332- return null;
333+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
334 }));
335
336 // this signal handler gets called when activate is called with PREVIEW_RESULT
337@@ -1187,7 +1228,8 @@
338 var mangled_uri = lens_results_model.get_string (iter, 0);
339
340 Unity.Protocol.Preview? reconstructed = null;
341- call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>
342+ var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
343+ call_lens_activate (mangled_uri, action_type, (reply) =>
344 {
345 var v = reply.get_child_value (0);
346 Unity.Protocol.ActivationReplyRaw reply_struct =

Subscribers

People subscribed via source and target branches

to all changes: