Merge lp:~alexlauni/libunity/blacklist-crash-1029949 into lp:libunity

Proposed by Alex Launi
Status: Merged
Approved by: Alex Launi
Approved revision: 198
Merged at revision: 193
Proposed branch: lp:~alexlauni/libunity/blacklist-crash-1029949
Merge into: lp:libunity
Diff against target: 301 lines (+134/-69)
5 files modified
src/unity-sound-menu-mpris.vala (+18/-19)
test/vala/Makefile.am (+60/-49)
test/vala/Makefile.integration_tests (+0/-1)
test/vala/blacklist-crash-1029949-test-case.vala (+44/-0)
test/vala/test-mpris-backend-server.vala (+12/-0)
To merge this branch: bzr merge lp:~alexlauni/libunity/blacklist-crash-1029949
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Łukasz Zemczak Approve
Conor Curran Pending
Review via email: mp+131445@code.launchpad.net

Commit message

Fix crash when adding or removing players from the blacklist

Description of the change

Fixes segfault from non-null terminated array being passed to gsettings set_strv

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

Built and tested with the test case - no crash or problems visible, no regressions as well. +1 for me. So I approve this in overall.

Just two things 'needing fixing'. First - is the printf necessary? It would be best if it was gone ;)

Second thing - could you actually add a test for this bug in this merge request? You could modify the vala test case that you have attached to the bug earlier. It's necessary that all things that can be actually tested land with tests.

review: Needs Fixing
Revision history for this message
Alex Launi (alexlauni) wrote :

Ha. Forgot to clear that out. Whoops. fiXXXed.

As for the test. A lot of libunity's test suite has been disabled. I don't have the time to fix the test suite, Ronoc said he'd find some time, but I've added a test so it'll be ready when ronoc fixes the suite.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

LGTM.

review: Approve
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Actually wait, I tried running the test (compiled with --enable-integration-tests=yes) ./test-mpris-backend and it seems to crash somehow. When I comment out the this.player.menu_player.is_blacklisted = true; line the test goes on fine. So I think maybe the test is a bit broken somewhere.

review: Needs Fixing
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

I think this is as good as it can get currently, without going the painful path of fixing the integration tests in libunity in overall. Those are still badly broken.

As I already poked you personally about, could we just quickly hack the autogen.sh to add this new test to be executed on make check? Would be most awesome.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Tested, works awesomely. Good to see you have found that other place causing the same bug, excellent work!
+1

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

FAILED: Autolanding.
No commit message was specified.

review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-sound-menu-mpris.vala'
2--- src/unity-sound-menu-mpris.vala 2012-09-20 19:52:53 +0000
3+++ src/unity-sound-menu-mpris.vala 2012-10-30 09:13:23 +0000
4@@ -376,30 +376,29 @@
5 }
6
7 private void add_to_blacklist ()
8- {
9- var already_bl = this.settings.get_strv ("blacklisted-media-players");
10- var new_bl = new ArrayList<string>();
11-
12- foreach (var s in already_bl){
13- if ( s == get_blacklist_name()) return;
14- Trace.log_object (this, "add_to_blacklist: %s", s);
15- new_bl.add(s);
16+ {
17+ var blacklist = new GLib.VariantBuilder (new VariantType("as"));
18+ foreach (var already_blacklisted in this.settings.get_strv("blacklisted-media-players"))
19+ {
20+ if (already_blacklisted == get_blacklist_name ())
21+ return;
22+ blacklist.add("s", already_blacklisted);
23 }
24- new_bl.add (get_blacklist_name());
25- this.settings.set_strv ("blacklisted-media-players",
26- new_bl.to_array());
27+ blacklist.add("s", get_blacklist_name());
28+
29+ this.settings.set_value("blacklisted-media-players", blacklist.end());
30 }
31
32- private void remove_from_blacklist ()
33+ private void remove_from_blacklist()
34 {
35- var already_bl = this.settings.get_strv ("blacklisted-media-players");
36- var new_bl = new ArrayList<string>();
37- foreach (string s in already_bl){
38- if ( s == get_blacklist_name() )continue;
39- new_bl.add(s);
40+ var blacklist = new GLib.VariantBuilder(new VariantType("as"));
41+ foreach (var already_blacklisted in this.settings.get_strv("blacklisted-media-players"))
42+ {
43+ if (already_blacklisted == get_blacklist_name())
44+ continue;
45+ blacklist.add(already_blacklisted);
46 }
47- this.settings.set_strv( "blacklisted-media-players",
48- new_bl.to_array());
49+ this.settings.set_value("blacklisted-media-players", blacklist.end());
50 }
51 }
52 /****************************************************************************************/
53
54=== modified file 'test/vala/Makefile.am'
55--- test/vala/Makefile.am 2012-10-26 14:42:43 +0000
56+++ test/vala/Makefile.am 2012-10-30 09:13:23 +0000
57@@ -2,57 +2,57 @@
58
59 DISTCHECK_CONFIGURE_FLAGS = --enable-integration-tests=no
60
61-check_PROGRAMS = test-vala test-lens test-remote-scope
62+check_PROGRAMS = test-vala test-lens test-remote-scope test-blacklist-crash
63
64 AM_CPPFLAGS = \
65- -I$(top_srcdir) \
66- -I$(top_builddir)/protocol \
67- -I$(top_builddir)/src \
68- -DBUILDDIR=\"$(top_builddir)\" \
69- -DTESTDIR=\"$(top_srcdir)/test\" \
70- -DTESTVALADIR=\"$(top_srcdir)/test/vala\" \
71- -DG_SETTINGS_ENABLE_BACKEND \
72- $(LIBUNITY_CFLAGS) \
73- $(LIBUNITY_LIBS)
74+ -I$(top_srcdir) \
75+ -I$(top_builddir)/protocol \
76+ -I$(top_builddir)/src \
77+ -DBUILDDIR=\"$(top_builddir)\" \
78+ -DTESTDIR=\"$(top_srcdir)/test\" \
79+ -DTESTVALADIR=\"$(top_srcdir)/test/vala\" \
80+ -DG_SETTINGS_ENABLE_BACKEND \
81+ $(LIBUNITY_CFLAGS) \
82+ $(LIBUNITY_LIBS)
83
84-if !ENABLE_C_WARNINGS
85- AM_CPPFLAGS += -w
86+if ENABLE_C_WARNINGS
87+ AM_CPPFLAGS += -w
88 endif
89
90 if ENABLE_TRACE_LOG
91- AM_CPPFLAGS += -DENABLE_UNITY_TRACE_LOG
92+ AM_CPPFLAGS += -DENABLE_UNITY_TRACE_LOG
93 endif
94
95 AM_VALAFLAGS = \
96- --vapidir=$(top_builddir)/src \
97- --vapidir=$(top_builddir)/protocol \
98- --vapidir=$(top_srcdir)/test/vala \
99- --pkg unity-protocol \
100- --pkg unity-internal \
101- --pkg config \
102- $(LIBUNITY_PACKAGES) \
103- $(MAINTAINER_VALAFLAGS) \
104- $(NULL)
105+ --vapidir=$(top_builddir)/src \
106+ --vapidir=$(top_builddir)/protocol \
107+ --vapidir=$(top_srcdir)/test/vala \
108+ --pkg unity-protocol \
109+ --pkg unity-internal \
110+ --pkg config \
111+ $(LIBUNITY_PACKAGES) \
112+ $(MAINTAINER_VALAFLAGS) \
113+ $(NULL)
114
115 test_libs = \
116- $(top_builddir)/src/libunity.la \
117- $(top_builddir)/protocol/libunity-protocol-private.la \
118- $(LIBUNITY_LIBS)
119+ $(top_builddir)/src/libunity.la \
120+ $(top_builddir)/protocol/libunity-protocol-private.la \
121+ $(LIBUNITY_LIBS)
122
123-TEST_PROGS += test-vala test-lens
124+TEST_PROGS += test-vala test-lens test-blacklist-crash
125
126 test_vala_LDADD = $(test_libs)
127
128 test_vala_VALASOURCES = \
129- test-appinfo-manager.vala \
130- test-filters.vala \
131- test-io.vala \
132- test-launcher.vala \
133- test-preferences.vala \
134- test-previews.vala \
135- test-scope-signals.vala \
136- test-vala.vala \
137- $(NULL)
138+ test-appinfo-manager.vala \
139+ test-filters.vala \
140+ test-io.vala \
141+ test-launcher.vala \
142+ test-preferences.vala \
143+ test-previews.vala \
144+ test-scope-signals.vala \
145+ test-vala.vala \
146+ $(NULL)
147 nodist_test_vala_SOURCES = $(test_vala_VALASOURCES:.vala=.c)
148
149 test_lens_LDADD = $(test_libs)
150@@ -63,11 +63,16 @@
151 test_remote_scope_VALASOURCES = test-remote-scope.vala
152 nodist_test_remote_scope_SOURCES = $(test_remote_scope_VALASOURCES:.vala=.c)
153
154+test_blacklist_crash_LDADD = $(test_libs)
155+test_blacklist_crash_VALASOURCES = blacklist-crash-1029949-test-case.vala
156+nodist_test_blacklist_crash_SOURCES = $(test_blacklist_crash_VALASOURCES:.vala=.c)
157+
158 BUILT_SOURCES = \
159- test-vala.vala.stamp \
160- test-lens.vala.stamp \
161- test-remote-scope.vala.stamp \
162- $(NULL)
163+ test-vala.vala.stamp \
164+ test-lens.vala.stamp \
165+ test-remote-scope.vala.stamp \
166+ test-blacklist-crash.vala.stamp \
167+ $(NULL)
168
169 test-vala.vala.stamp: $(test_vala_VALASOURCES)
170 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
171@@ -81,19 +86,25 @@
172 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
173 @touch $@
174
175+test-blacklist-crash.vala.stamp: $(test_blacklist_crash_VALASOURCES)
176+ $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
177+ @touch $@
178+
179 include Makefile.integration_tests
180
181 EXTRA_DIST += \
182- $(test_vala_VALASOURCES) \
183- $(test_lens_VALASOURCES) \
184- $(test_remote_scope_VALASOURCES) \
185- config.vapi \
186- $(NULL)
187+ $(test_vala_VALASOURCES) \
188+ $(test_lens_VALASOURCES) \
189+ $(test_remote_scope_VALASOURCES) \
190+ $(test_blacklist_crash_VALASOURCES) \
191+ config.vapi \
192+ $(NULL)
193
194 CLEANFILES = \
195- *.stamp \
196- $(test_vala_VALASOURCES:.vala=.c) \
197- $(test_lens_VALASOURCES:.vala=.c) \
198- $(test_remote_scope_VALASOURCES:.vala=.c) \
199- $(NULL)
200+ *.stamp \
201+ $(test_vala_VALASOURCES:.vala=.c) \
202+ $(test_lens_VALASOURCES:.vala=.c) \
203+ $(test_remote_scope_VALASOURCES:.vala=.c) \
204+ $(test_blacklist_crash_VALASOURCES:.vala=.c) \
205+ $(NULL)
206
207
208=== modified file 'test/vala/Makefile.integration_tests'
209--- test/vala/Makefile.integration_tests 2012-08-07 12:31:44 +0000
210+++ test/vala/Makefile.integration_tests 2012-10-30 09:13:23 +0000
211@@ -139,4 +139,3 @@
212 test-mpris-backend-prop-updates-server.vala.stamp: $(test_mpris_backend_prop_updates_server_VALASOURCES)
213 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
214 @touch $@
215-
216
217=== added file 'test/vala/blacklist-crash-1029949-test-case.vala'
218--- test/vala/blacklist-crash-1029949-test-case.vala 1970-01-01 00:00:00 +0000
219+++ test/vala/blacklist-crash-1029949-test-case.vala 2012-10-30 09:13:23 +0000
220@@ -0,0 +1,44 @@
221+using Gee;
222+using Unity;
223+
224+
225+
226+int main(string[] args)
227+{
228+ int i = 0;
229+ var loop = new MainLoop();
230+ var time = new TimeoutSource(10);
231+ MusicPlayer test_player = null;
232+
233+ time.set_callback(() => {
234+ const string desktop_file_name = "rhythmbox.desktop";
235+ test_player = new MusicPlayer(desktop_file_name);
236+ test_player.export();
237+
238+ return false;
239+ });
240+ time.attach(loop.get_context());
241+
242+ var thread_timer = new TimeoutSource(100);
243+ thread_timer.set_callback(() => {
244+ set_blacklisted(test_player);
245+ if (++i < 100)
246+ return true;
247+ test_player.unexport();
248+ loop.quit();
249+ return false;
250+ });
251+ thread_timer.attach(loop.get_context());
252+
253+ loop.run();
254+
255+ return 0;
256+}
257+
258+void* set_blacklisted(MusicPlayer test_player)
259+{
260+ int raw_blacklist = Random.int_range(0, 2);
261+ bool blacklist = (bool) raw_blacklist;
262+ test_player.is_blacklisted = blacklist;
263+ return null;
264+}
265
266=== modified file 'test/vala/test-mpris-backend-server.vala'
267--- test/vala/test-mpris-backend-server.vala 2011-11-25 12:13:04 +0000
268+++ test/vala/test-mpris-backend-server.vala 2012-10-30 09:13:23 +0000
269@@ -16,6 +16,9 @@
270
271 public bool escape ()
272 {
273+ // this is some cleanup
274+ this.player.menu_player.is_blacklisted = false;
275+
276 this.mainloop.quit ();
277 return false;
278 }
279@@ -73,6 +76,8 @@
280 player.menu_player.player_menu = player_root;
281
282 player.menu_player.add_playlist (pl2);
283+
284+ Timeout.add (5, blacklist_self);
285
286 //The manual test of the playlistchanged signal, please leave commented
287 //Timeout.add (5, change_playlist_name);
288@@ -81,6 +86,13 @@
289 return false;
290 }
291
292+ // Regression test to ensure that setting blacklist does not cause a segfault
293+ public bool blacklist_self()
294+ {
295+ this.player.menu_player.is_blacklisted = true;
296+ return false;
297+ }
298+
299 // Manual test of the playlist name change signal
300 // Can't test this from the other side of dbus since there is no api to change
301 // or edit playlists yet ...

Subscribers

People subscribed via source and target branches