[PATCH 04/15] node: Fix unsafe pa_idxset_remove_by_index() call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If pa_node_unlink() was called before the node was added to
pa_core.nodes, then the pa_idxset_remove_by_index() call would remove
some innocent bystander, or it would fail, leading to an assertion
failure.
---
 src/pulsecore/node.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/node.c b/src/pulsecore/node.c
index 3ef35e3..c0408c2 100644
--- a/src/pulsecore/node.c
+++ b/src/pulsecore/node.c
@@ -131,6 +131,7 @@ pa_node *pa_node_new(pa_core *core, pa_node_new_data *data) {
 
     n = pa_xnew0(pa_node, 1);
     n->core = core;
+    n->index = PA_INVALID_INDEX;
 
     if (!(registered_name = pa_namereg_register(core, name, PA_NAMEREG_NODE, n, false))) {
         pa_log("Failed to register name %s.", name);
@@ -417,7 +418,10 @@ void pa_node_unlink(pa_node *node) {
     if (node->monitor_of)
         node->monitor_of->monitor = NULL;
 
-    pa_assert_se(pa_idxset_remove_by_index(node->core->nodes, node->index));
+    if (node->index != PA_INVALID_INDEX) {
+        pa_assert_se(pa_idxset_remove_by_index(node->core->nodes, node->index));
+        node->index = PA_INVALID_INDEX;
+    }
 
 }
 
-- 
1.8.3.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux