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
=== modified file 'protocol/protocol-lens-interface.vala'
--- protocol/protocol-lens-interface.vala 2012-09-04 11:40:42 +0000
+++ protocol/protocol-lens-interface.vala 2012-10-17 08:16:32 +0000
@@ -38,6 +38,15 @@
38 public HashTable<string, Variant> hints;38 public HashTable<string, Variant> hints;
39}39}
4040
41/* The error types that can be thrown from DBus methods */
42[DBus (name = "com.canonical.Unity.LensError")]
43public errordomain LensError
44{
45 FAILED,
46 INVALID_SCOPE
47}
48
49
41public enum HandledType50public enum HandledType
42{51{
43 NOT_HANDLED,52 NOT_HANDLED,
@@ -74,12 +83,12 @@
7483
75 // FIXME: should have the hints param and activate_with_hints should go away84 // FIXME: should have the hints param and activate_with_hints should go away
76 public async abstract ActivationReplyRaw activate (85 public async abstract ActivationReplyRaw activate (
77 string uri, uint action_type) throws IOError;86 string uri, uint action_type) throws IOError, LensError;
7887
79 public async abstract ActivationReplyRaw activate_with_hints (88 public async abstract ActivationReplyRaw activate_with_hints (
80 string uri, uint action_type, HashTable<string, Variant> hints) throws IOError;89 string uri, uint action_type, HashTable<string, Variant> hints) throws IOError, LensError;
8190
82 public async abstract HashTable<string, Variant> update_preview_property (string uri, HashTable<string, Variant> values) throws IOError;91 public async abstract HashTable<string, Variant> update_preview_property (string uri, HashTable<string, Variant> values) throws IOError, LensError;
8392
84 public async abstract HashTable<string, Variant> search (93 public async abstract HashTable<string, Variant> search (
85 string search_string, HashTable<string, Variant> hints) throws IOError;94 string search_string, HashTable<string, Variant> hints) throws IOError;
8695
=== modified file 'src/unity-lens-private.vala'
--- src/unity-lens-private.vala 2012-09-04 11:40:42 +0000
+++ src/unity-lens-private.vala 2012-10-17 08:16:32 +0000
@@ -493,8 +493,8 @@
493 queue_info_changed ();493 queue_info_changed ();
494 }494 }
495495
496 public async ActivationReplyRaw activate (string uri,496 public async ActivationReplyRaw activate (
497 uint action_type) throws IOError497 string uri, uint action_type) throws IOError, LensError
498 {498 {
499 var hints = new HashTable<string, Variant> (null, null);499 var hints = new HashTable<string, Variant> (null, null);
500 var reply = yield activate_with_hints (uri, action_type, hints);500 var reply = yield activate_with_hints (uri, action_type, hints);
@@ -503,7 +503,7 @@
503503
504 public async ActivationReplyRaw activate_with_hints (504 public async ActivationReplyRaw activate_with_hints (
505 string uri, uint action_type,505 string uri, uint action_type,
506 HashTable<string, Variant> hints) throws IOError506 HashTable<string, Variant> hints) throws IOError, LensError
507 {507 {
508 string[] tokens;508 string[] tokens;
509 ScopeProxy? scope = null;509 ScopeProxy? scope = null;
@@ -513,11 +513,15 @@
513 {513 {
514 case ActionType.PREVIEW_ACTION:514 case ActionType.PREVIEW_ACTION:
515 tokens = uri.split (":", 3);515 tokens = uri.split (":", 3);
516 if (tokens.length < 3)
517 throw new LensError.FAILED ("Malformatted URI parameter");
516 scope = get_scope_for_uid (tokens[1]);518 scope = get_scope_for_uid (tokens[1]);
517 scope_uri = "%s:%s".printf (tokens[0], tokens[2]);519 scope_uri = "%s:%s".printf (tokens[0], tokens[2]);
518 break;520 break;
519 default:521 default:
520 tokens = uri.split (":", 2);522 tokens = uri.split (":", 2);
523 if (tokens.length < 2)
524 throw new LensError.FAILED ("Malformatted URI parameter");
521 scope = get_scope_for_uid (tokens[0]);525 scope = get_scope_for_uid (tokens[0]);
522 scope_uri = tokens[1];526 scope_uri = tokens[1];
523 break;527 break;
@@ -535,7 +539,7 @@
535 else539 else
536 {540 {
537 warning ("Unable to find scope for activation request: %s", uri);541 warning ("Unable to find scope for activation request: %s", uri);
538 raw.uri = uri;542 throw new LensError.INVALID_SCOPE ("Invalid URI parameter");
539 }543 }
540544
541 // FIXME: do we need to mangle uris/actions that the scope provided?545 // FIXME: do we need to mangle uris/actions that the scope provided?
@@ -546,11 +550,14 @@
546 return raw;550 return raw;
547 }551 }
548552
549 public async HashTable<string, Variant> update_preview_property (string uri,553 public async HashTable<string, Variant> update_preview_property (
550 HashTable<string, Variant> values) throws IOError554 string uri, HashTable<string, Variant> values) throws IOError, LensError
551 {555 {
552 string[] tokens = uri.split (":", 2);556 string[] tokens = uri.split (":", 2);
553 string? scope_uri = tokens[1];557 if (tokens.length < 2)
558 throw new LensError.FAILED ("Malformatted URI parameter");
559
560 string scope_uri = tokens[1];
554 ScopeProxy? scope = get_scope_for_uid (tokens[0]);561 ScopeProxy? scope = get_scope_for_uid (tokens[0]);
555 562
556 if (scope is ScopeProxy)563 if (scope is ScopeProxy)
@@ -561,6 +568,7 @@
561 else568 else
562 {569 {
563 warning ("Unable to find scope for activation request: %s", uri);570 warning ("Unable to find scope for activation request: %s", uri);
571 throw new LensError.INVALID_SCOPE ("Invalid URI parameter");
564 }572 }
565573
566 return new HashTable<string, Variant> (str_hash, str_equal);574 return new HashTable<string, Variant> (str_hash, str_equal);
567575
=== modified file 'test/vala/test-lens.vala'
--- test/vala/test-lens.vala 2012-10-02 16:16:29 +0000
+++ test/vala/test-lens.vala 2012-10-17 08:16:32 +0000
@@ -54,6 +54,7 @@
54 Test.add_data_func ("/Unit/Lens/ReplyHint", test_lens_reply_hint);54 Test.add_data_func ("/Unit/Lens/ReplyHint", test_lens_reply_hint);
55 Test.add_data_func ("/Unit/Lens/Sources", test_lens_sources);55 Test.add_data_func ("/Unit/Lens/Sources", test_lens_sources);
56 Test.add_data_func ("/Unit/Lens/Activation", test_lens_activation);56 Test.add_data_func ("/Unit/Lens/Activation", test_lens_activation);
57 Test.add_data_func ("/Unit/Lens/InvalidActivation", test_lens_invalid_activation);
57 Test.add_data_func ("/Unit/Lens/Preview", test_lens_preview);58 Test.add_data_func ("/Unit/Lens/Preview", test_lens_preview);
58 Test.add_data_func ("/Unit/Lens/Preview/Async", test_lens_preview_async);59 Test.add_data_func ("/Unit/Lens/Preview/Async", test_lens_preview_async);
59 Test.add_data_func ("/Unit/Lens/Preview/AsyncWithNull", test_lens_preview_async_with_null);60 Test.add_data_func ("/Unit/Lens/Preview/AsyncWithNull", test_lens_preview_async_with_null);
@@ -163,9 +164,10 @@
163 assert (scope_up == true);164 assert (scope_up == true);
164 }165 }
165166
166 private static void call_lens_method (string method_name, 167 private static void call_lens_method (string method_name,
167 Variant? parameters,168 Variant? parameters,
168 Func<Variant?>? cb)169 Func<Variant?>? cb,
170 Func<Error?>? error_cb = null)
169 {171 {
170 DBusConnection? bus = null;172 DBusConnection? bus = null;
171 try173 try
@@ -190,35 +192,43 @@
190 var reply = bus.call.end (res);192 var reply = bus.call.end (res);
191 if (cb != null) cb (reply);193 if (cb != null) cb (reply);
192 }194 }
193 catch (Error e)195 catch (Error err)
194 {196 {
195 warning ("%s", e.message);197 if (error_cb != null)
198 error_cb (err);
199 else
200 warning ("%s", err.message);
196 }201 }
197 });202 });
198 }203 }
199204
200 private static void call_lens_search (string search_string,205 private static void call_lens_search (string search_string,
201 Func<Variant?>? cb = null)206 Func<Variant?>? cb = null,
207 Func<Error?>? error_cb = null)
202 {208 {
203 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));209 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));
204 vb.add ("s", search_string);210 vb.add ("s", search_string);
205 vb.open (new VariantType ("a{sv}"));211 vb.open (new VariantType ("a{sv}"));
206 vb.close ();212 vb.close ();
207213
208 call_lens_method ("Search", vb.end (), cb);214 call_lens_method ("Search", vb.end (), cb, error_cb);
209 }215 }
210216
211 private static void call_lens_activate (string uri, uint action_type,217 private static void call_lens_activate (string uri,
212 Func<Variant?>? cb = null)218 Unity.Protocol.ActionType action_type,
219 Func<Variant?>? cb = null,
220 Func<Error?>? error_cb = null)
213 {221 {
214 call_lens_activate_with_hints (uri, action_type,222 call_lens_activate_with_hints (uri, action_type,
215 new HashTable<string, Variant> (null, null),223 new HashTable<string, Variant> (null, null),
216 cb);224 cb, error_cb);
217 }225 }
218226
219 private static void call_lens_activate_with_hints (227 private static void call_lens_activate_with_hints (
220 string uri, uint action_type, HashTable<string, Variant> hints,228 string uri, Unity.Protocol.ActionType action_type,
221 Func<Variant?>? cb = null)229 HashTable<string, Variant> hints,
230 Func<Variant?>? cb = null,
231 Func<Error?>? error_cb = null)
222 {232 {
223 Variant parameters;233 Variant parameters;
224 // let's make sure we test both variants, since we have to support them234 // let's make sure we test both variants, since we have to support them
@@ -227,24 +237,25 @@
227 Variant ht = hints;237 Variant ht = hints;
228 parameters = new Variant ("(su@a{sv})", uri, action_type, ht);238 parameters = new Variant ("(su@a{sv})", uri, action_type, ht);
229239
230 call_lens_method ("ActivateWithHints", parameters, cb);240 call_lens_method ("ActivateWithHints", parameters, cb, error_cb);
231 }241 }
232 else242 else
233 {243 {
234 parameters = new Variant ("(su)", uri, action_type);244 parameters = new Variant ("(su)", uri, action_type);
235245
236 call_lens_method ("Activate", parameters, cb);246 call_lens_method ("Activate", parameters, cb, error_cb);
237 }247 }
238 }248 }
239249
240 private static void call_lens_update_preview_property (string uri, HashTable<string, Variant> props,250 private static void call_lens_update_preview_property (string uri, HashTable<string, Variant> props,
241 Func<Variant?>? cb = null)251 Func<Variant?>? cb = null,
252 Func<Error?>? error_cb = null)
242 {253 {
243 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));254 var vb = new VariantBuilder (new VariantType ("(sa{sv})"));
244 vb.add ("s", uri);255 vb.add ("s", uri);
245 vb.add_value (props);256 vb.add_value (props);
246257
247 call_lens_method ("UpdatePreviewProperty", vb.end(), cb);258 call_lens_method ("UpdatePreviewProperty", vb.end(), cb, error_cb);
248 }259 }
249 260
250 public static void test_lens_search ()261 public static void test_lens_search ()
@@ -747,7 +758,8 @@
747 }));758 }));
748759
749 ml = new MainLoop ();760 ml = new MainLoop ();
750 call_lens_activate (mangled_uri, 0, () =>761 var action = Unity.Protocol.ActionType.ACTIVATE_RESULT;
762 call_lens_activate (mangled_uri, action, () =>
751 {763 {
752 ml.quit ();764 ml.quit ();
753 });765 });
@@ -756,6 +768,28 @@
756 assert (got_activate_uri_signal);768 assert (got_activate_uri_signal);
757 }769 }
758770
771 public static void test_lens_invalid_activation ()
772 {
773 // ignore warnings
774 Test.log_set_fatal_handler (() => { return false; });
775 Unity.Protocol.ActionType action;
776 var ml = new MainLoop ();
777
778 Func<Error?> err_cb = (err) =>
779 {
780 assert (err is Unity.Protocol.LensError);
781 ml.quit ();
782 };
783 action = Unity.Protocol.ActionType.ACTIVATE_RESULT;
784 call_lens_activate ("", action, null, err_cb);
785 assert (run_with_timeout (ml, 5000));
786
787 ml = new MainLoop ();
788 action = Unity.Protocol.ActionType.PREVIEW_RESULT;
789 call_lens_activate (":", action, null, err_cb);
790 assert (run_with_timeout (ml, 5000));
791 }
792
759 public static void test_lens_preview ()793 public static void test_lens_preview ()
760 {794 {
761 SignalWrapper[] signals = null;795 SignalWrapper[] signals = null;
@@ -792,7 +826,8 @@
792826
793 ml = new MainLoop ();827 ml = new MainLoop ();
794 Unity.Protocol.Preview? reconstructed = null;828 Unity.Protocol.Preview? reconstructed = null;
795 call_lens_activate (mangled_uri, 1, (reply) =>829 var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
830 call_lens_activate (mangled_uri, action_type, (reply) =>
796 {831 {
797 var v = reply.get_child_value (0);832 var v = reply.get_child_value (0);
798 Unity.Protocol.ActivationReplyRaw reply_struct =833 Unity.Protocol.ActivationReplyRaw reply_struct =
@@ -816,7 +851,9 @@
816851
817 // expecting button_id:scope_uid:uri852 // expecting button_id:scope_uid:uri
818 ml = new MainLoop ();853 ml = new MainLoop ();
819 call_lens_activate ("%s:%s".printf (action.id, mangled_uri), 2, (reply) =>854 action_type = Unity.Protocol.ActionType.PREVIEW_ACTION;
855 var activate_uri = "%s:%s".printf (action.id, mangled_uri);
856 call_lens_activate (activate_uri, action_type, (reply) =>
820 {857 {
821 ml.quit ();858 ml.quit ();
822 });859 });
@@ -871,7 +908,8 @@
871908
872 ml = new MainLoop ();909 ml = new MainLoop ();
873 Unity.Protocol.Preview? reconstructed = null;910 Unity.Protocol.Preview? reconstructed = null;
874 call_lens_activate (mangled_uri, 1, (reply) =>911 var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
912 call_lens_activate (mangled_uri, action_type, (reply) =>
875 {913 {
876 var v = reply.get_child_value (0);914 var v = reply.get_child_value (0);
877 Unity.Protocol.ActivationReplyRaw reply_struct =915 Unity.Protocol.ActivationReplyRaw reply_struct =
@@ -897,7 +935,9 @@
897935
898 // expecting button_id:scope_uid:uri936 // expecting button_id:scope_uid:uri
899 ml = new MainLoop ();937 ml = new MainLoop ();
900 call_lens_activate ("%s:%s".printf (action.id, mangled_uri), 2, (reply) =>938 action_type = Unity.Protocol.ActionType.PREVIEW_ACTION;
939 var activate_uri = "%s:%s".printf (action.id, mangled_uri);
940 call_lens_activate (activate_uri, action_type, (reply) =>
901 {941 {
902 ml.quit ();942 ml.quit ();
903 });943 });
@@ -945,7 +985,8 @@
945985
946 ml = new MainLoop ();986 ml = new MainLoop ();
947 Unity.Protocol.Preview? reconstructed = null;987 Unity.Protocol.Preview? reconstructed = null;
948 call_lens_activate (mangled_uri, 1, (reply) =>988 var action = Unity.Protocol.ActionType.PREVIEW_RESULT;
989 call_lens_activate (mangled_uri, action, (reply) =>
949 {990 {
950 var v = reply.get_child_value (0);991 var v = reply.get_child_value (0);
951 Unity.Protocol.ActivationReplyRaw reply_struct =992 Unity.Protocol.ActivationReplyRaw reply_struct =
@@ -979,7 +1020,6 @@
979 bool got_preview_uri_signal = false;1020 bool got_preview_uri_signal = false;
980 string? request_item_signal_uri = null;1021 string? request_item_signal_uri = null;
981 int request_item_signal_count = 0;1022 int request_item_signal_count = 0;
982 Unity.PreviewAction? action = null;
9831023
984 signals += new SignalWrapper (local_scope,1024 signals += new SignalWrapper (local_scope,
985 local_scope.activate_uri.connect ((uri) =>1025 local_scope.activate_uri.connect ((uri) =>
@@ -1113,7 +1153,8 @@
1113 var mangled_uri = lens_results_model.get_string (iter, 0);1153 var mangled_uri = lens_results_model.get_string (iter, 0);
11141154
1115 Unity.Protocol.GenericPreview? reconstructed = null;1155 Unity.Protocol.GenericPreview? reconstructed = null;
1116 call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>1156 var action = Unity.Protocol.ActionType.PREVIEW_RESULT;
1157 call_lens_activate (mangled_uri, action, (reply) =>
1117 {1158 {
1118 var v = reply.get_child_value (0);1159 var v = reply.get_child_value (0);
1119 Unity.Protocol.ActivationReplyRaw reply_struct =1160 Unity.Protocol.ActivationReplyRaw reply_struct =
@@ -1167,7 +1208,7 @@
1167 {1208 {
1168 got_activated_signal = true;1209 got_activated_signal = true;
1169 assert (action.hints["passing-extra-info"].get_boolean () == true);1210 assert (action.hints["passing-extra-info"].get_boolean () == true);
1170 return null;1211 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
1171 }));1212 }));
11721213
1173 // this signal handler gets called when activate is called with PREVIEW_RESULT1214 // this signal handler gets called when activate is called with PREVIEW_RESULT
@@ -1187,7 +1228,8 @@
1187 var mangled_uri = lens_results_model.get_string (iter, 0);1228 var mangled_uri = lens_results_model.get_string (iter, 0);
11881229
1189 Unity.Protocol.Preview? reconstructed = null;1230 Unity.Protocol.Preview? reconstructed = null;
1190 call_lens_activate (mangled_uri, Unity.Protocol.ActionType.PREVIEW_RESULT, (reply) =>1231 var action_type = Unity.Protocol.ActionType.PREVIEW_RESULT;
1232 call_lens_activate (mangled_uri, action_type, (reply) =>
1191 {1233 {
1192 var v = reply.get_child_value (0);1234 var v = reply.get_child_value (0);
1193 Unity.Protocol.ActivationReplyRaw reply_struct =1235 Unity.Protocol.ActivationReplyRaw reply_struct =

Subscribers

People subscribed via source and target branches

to all changes: