dee

Merge lp:~mhr3/dee/fix-963991 into lp:dee

Proposed by Michal Hruby
Status: Merged
Approved by: Michal Hruby
Approved revision: 363
Merged at revision: 361
Proposed branch: lp:~mhr3/dee/fix-963991
Merge into: lp:dee
Diff against target: 75 lines (+48/-1)
2 files modified
src/dee-tree-index.c (+1/-1)
tests/test-index.c (+47/-0)
To merge this branch: bzr merge lp:~mhr3/dee/fix-963991
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+100380@code.launchpad.net

Commit message

Prevent a possible crash when prefix searching near the end of sequence

Description of the change

Prefix searching near the end of the index sequence could cause a crash because we were calling g_sequence_get on the end iterator followed by dereferencing of a (possibly) NULL pointer.

Added a check whether the found iterator isn't end iterator.

Also added unit test for the issue.

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

seems good

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No commit message specified.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Well, spotted. Rock on dude.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dee-tree-index.c'
2--- src/dee-tree-index.c 2012-03-16 11:48:56 +0000
3+++ src/dee-tree-index.c 2012-04-02 10:51:21 +0000
4@@ -266,7 +266,7 @@
5 if (g_str_has_prefix (term_result->term, term)) iter = previous;
6 else break;
7 }
8- if (iter == found_iter)
9+ if (iter == found_iter && iter != end)
10 {
11 /* We never checked this one */
12 term_result = g_sequence_get (iter);
13
14=== modified file 'tests/test-index.c'
15--- tests/test-index.c 2012-02-28 09:59:38 +0000
16+++ tests/test-index.c 2012-04-02 10:51:21 +0000
17@@ -505,6 +505,47 @@
18 g_assert_cmpint (dee_index_get_n_rows (fix->index), ==, 0);
19
20 }
21+
22+static void
23+test_prefix_search_empty (Fixture *fix, gconstpointer data)
24+{
25+ DeeResultSet *rs;
26+
27+ g_assert_cmpint (dee_index_get_n_rows (fix->index), ==, 0);
28+
29+ rs = dee_index_lookup (fix->index, "a", DEE_TERM_MATCH_PREFIX);
30+ g_assert_cmpuint (0, ==, dee_result_set_get_n_rows (rs));
31+ g_object_unref (rs);
32+}
33+
34+static void
35+test_prefix_search_near_beginning (Fixture *fix, gconstpointer data)
36+{
37+ DeeResultSet *rs;
38+
39+ dee_model_append (fix->model, "vl", 44);
40+
41+ g_assert_cmpint (dee_index_get_n_rows (fix->index), ==, 1);
42+
43+ rs = dee_index_lookup (fix->index, "a", DEE_TERM_MATCH_PREFIX);
44+ g_assert_cmpuint (0, ==, dee_result_set_get_n_rows (rs));
45+ g_object_unref (rs);
46+}
47+
48+static void
49+test_prefix_search_near_end (Fixture *fix, gconstpointer data)
50+{
51+ DeeResultSet *rs;
52+
53+ dee_model_append (fix->model, "a", 44);
54+
55+ g_assert_cmpint (dee_index_get_n_rows (fix->index), ==, 1);
56+
57+ rs = dee_index_lookup (fix->index, "vl", DEE_TERM_MATCH_PREFIX);
58+ g_assert_cmpuint (0, ==, dee_result_set_get_n_rows (rs));
59+ g_object_unref (rs);
60+}
61+
62 void
63 test_hash_index_create_suite (void)
64 {
65@@ -544,4 +585,10 @@
66 setup_text_tree, test_prefix_3_rows, teardown);
67 g_test_add ("/Index/Tree/Prefix4RowsAndClear", Fixture, 0,
68 setup_text_tree, test_prefix_4_rows_and_clear, teardown);
69+ g_test_add ("/Index/Tree/PrefixSearchEmpty", Fixture, 0,
70+ setup_text_tree, test_prefix_search_empty, teardown);
71+ g_test_add ("/Index/Tree/PrefixSearchNearBeginning", Fixture, 0,
72+ setup_text_tree, test_prefix_search_near_beginning, teardown);
73+ g_test_add ("/Index/Tree/PrefixSearchNearEnd", Fixture, 0,
74+ setup_text_tree, test_prefix_search_near_end, teardown);
75 }

Subscribers

People subscribed via source and target branches

to all changes: