Skip to content

cgraph: fix type confusion when updating node-by-id set

Matthew Fernandez requested to merge smattr/graphviz:smattr/gitlab-2300 into main

Graphs track their contained nodes in several collections, one of which is a set indexed on node ID (Agraph_t.n_id). Despite the intuition one might have from its name and comments, this set contains not Agnode_t * values but Agsubnode_t * values. dict_relabel, in attempting to delete and re-add a node using an Agnode_t * key instead of Agsubnode_t *, triggered invalid pointer reads and writes effectively corrupting the set. Due to the permissive interface of libcdt (dtinsert and dtinsert are macros that cast their value input parameter to void *, thwarting type correctness), the compiler was unable to spot this misuse.

This change completes the other half of the fix begun in f48e7e4d.

Curiously (1) this change combined with f48e7e4d suggest this code has never worked at all and (2) the comments removed in this commit suggest the original author was both aware of the problem as well as its fix.

Gitlab: fixes #2300 (closed)

Merge request reports