Skip to content

Commit

Permalink
dsync: Fix potential crash when handling mailbox renames
Browse files Browse the repository at this point in the history
Fixes:
Panic: file dsync-mailbox-tree-sync.c: line 575 (node_mailbox_trees_cmp): assertion failed: (ret != 0)
  • Loading branch information
sirainen committed Oct 17, 2024
1 parent 218ea7c commit 16de26f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/doveadm/dsync/dsync-mailbox-tree-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@ sync_find_branch(struct dsync_mailbox_tree *tree,
for (node = dir_node->first_child; node != NULL; node = node->next) {
if (dsync_mailbox_node_is_dir(node)) {
other_node = sync_find_branch(tree, other_tree, node);
if (other_node != NULL)
return other_node;
if (other_node != NULL && other_node->parent != NULL)
return other_node->parent;
} else {
guid_p = node->mailbox_guid;
other_node = hash_table_lookup(other_tree->guid_hash,
Expand Down
39 changes: 39 additions & 0 deletions src/doveadm/dsync/test-dsync-mailbox-tree-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,43 @@ static void test_dsync_mailbox_tree_sync_renames22(void)
test_end();
}

static void test_dsync_mailbox_tree_sync_renames23(void)
{
struct dsync_mailbox_tree *tree1, *tree2;

test_begin("dsync mailbox tree sync renames 23");
tree1 = dsync_mailbox_tree_init('/', '\0', '_');
tree2 = dsync_mailbox_tree_init('/', '\0', '_');

node_create(tree1, 2, "p1/a/c", 0);
node_create(tree1, 3, "p2/a/c", 0);

node_create(tree2, 4, "p2/b/d", 0);
node_create(tree2, 2, "p1", 0);

test_trees(tree1, tree2);
test_end();
}

static void test_dsync_mailbox_tree_sync_renames24(void)
{
struct dsync_mailbox_tree *tree1, *tree2;

test_begin("dsync mailbox tree sync renames 24");
tree1 = dsync_mailbox_tree_init('/', '\0', '_');
tree2 = dsync_mailbox_tree_init('/', '\0', '_');

node_create(tree1, 1, "p1/a", 0);
node_create(tree1, 2, "p1/a/c", 0);
node_create(tree1, 3, "p2/a/c", 0);

node_create(tree2, 4, "p2/b/d", 0);
node_create(tree2, 2, "p1", 0);

test_trees(tree1, tree2);
test_end();
}

static void test_dsync_mailbox_tree_sync_random(void)
{
struct dsync_mailbox_tree *tree1, *tree2;
Expand Down Expand Up @@ -779,6 +816,8 @@ int main(void)
test_dsync_mailbox_tree_sync_renames20,
test_dsync_mailbox_tree_sync_renames21,
test_dsync_mailbox_tree_sync_renames22,
test_dsync_mailbox_tree_sync_renames23,
test_dsync_mailbox_tree_sync_renames24,
test_dsync_mailbox_tree_sync_random,
NULL
};
Expand Down

0 comments on commit 16de26f

Please sign in to comment.