Skip to content

Commit 2123adf

Browse files
committed
CVE-2018-10756: Fix heap-use-after-free in tr_variantWalk
In libtransmission/variant.c, function tr_variantWalk, when the variant stack is reallocated, a pointer to the previously allocated memory region is kept. This address is later accessed (heap use-after-free) while walking back down the stack, causing the application to crash. The application can be any application which uses libtransmission, such as transmission-daemon, transmission-gtk, transmission-show, etc. Reported-by: Tom Richards <tom@tomrichards.net>
1 parent a6482b0 commit 2123adf

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

libtransmission/variant.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static int compareKeyIndex(void const* va, void const* vb)
758758
struct SaveNode
759759
{
760760
tr_variant const* v;
761-
tr_variant sorted;
761+
tr_variant* sorted;
762762
size_t childIndex;
763763
bool isVisited;
764764
};
@@ -783,30 +783,36 @@ static void nodeConstruct(struct SaveNode* node, tr_variant const* v, bool sort_
783783

784784
qsort(tmp, n, sizeof(struct KeyIndex), compareKeyIndex);
785785

786-
tr_variantInitDict(&node->sorted, n);
786+
node->sorted = tr_new(tr_variant, 1);
787+
tr_variantInitDict(node->sorted, n);
787788

788789
for (size_t i = 0; i < n; ++i)
789790
{
790-
node->sorted.val.l.vals[i] = *tmp[i].val;
791+
node->sorted->val.l.vals[i] = *tmp[i].val;
791792
}
792793

793-
node->sorted.val.l.count = n;
794+
node->sorted->val.l.count = n;
794795

795796
tr_free(tmp);
796797

797-
node->v = &node->sorted;
798+
v = node->sorted;
798799
}
799800
else
800801
{
801-
node->v = v;
802+
node->sorted = NULL;
802803
}
804+
805+
node->v = v;
803806
}
804807

805808
static void nodeDestruct(struct SaveNode* node)
806809
{
807-
if (node->v == &node->sorted)
810+
TR_ASSERT(node != NULL);
811+
812+
if (node->sorted != NULL)
808813
{
809-
tr_free(node->sorted.val.l.vals);
814+
tr_free(node->sorted->val.l.vals);
815+
tr_free(node->sorted);
810816
}
811817
}
812818

0 commit comments

Comments
 (0)