From 00ff9cd08fdb7e9b330188658f5b4c1dd488f1bf Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 6 Jun 2014 08:20:15 -0400 Subject: [PATCH] playlist: Fix a null pointer dereference in init() This happens if we try to use the Banned playlist before it exists in the database. Signed-off-by: Anna Schumaker --- core/playlist.cpp | 3 +++ tests/deck.cpp | 2 ++ tests/playlist.cpp | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/playlist.cpp b/core/playlist.cpp index c77a4f6e..06629d74 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -42,6 +42,9 @@ void playlist :: init() playlist_db.load(); IndexEntry *ent = get_tracks("Banned"); + if (!ent) + return; + for (it = ent->values.begin(); it != ent->values.end(); it++) library :: get_queue()->del(tagdb :: lookup(*it)); } diff --git a/tests/deck.cpp b/tests/deck.cpp index 339f1d46..f1f8939d 100644 --- a/tests/deck.cpp +++ b/tests/deck.cpp @@ -153,6 +153,8 @@ static void test_next_prev() int main(int argc, char **argv) { + test :: rm_data_dir(); + run_test("Deck Init Test", test_init); run_test("Deck Create, Move and Destroy Test", test_create_mv_destroy); run_test("Deck Next and Prev Test", test_next_prev); diff --git a/tests/playlist.cpp b/tests/playlist.cpp index 1308cd9b..7c141071 100644 --- a/tests/playlist.cpp +++ b/tests/playlist.cpp @@ -18,6 +18,10 @@ static void test_init() test_equal(q->has_flag(Q_REPEAT), true); test_equal(q->has_flag(Q_NO_SORT), true); + /* init should work even if playlist.db doesn't exist! */ + playlist :: init(); + + test :: cp_data_dir(); tagdb :: init(); library :: init(); playlist :: init(); @@ -110,7 +114,7 @@ static void test_has() int main(int argc, char **argv) { - test :: cp_data_dir(); + test :: rm_data_dir(); run_test("Playlist Initialization Test", test_init); run_test("Playlist Queue Test", test_queue);