]> granicus.if.org Git - graphviz/commitdiff
Fixed: 'dereference before null check' in DotIO.c
authorErwin Janssen <erwinjanssen@outlook.com>
Sat, 19 Nov 2016 01:20:46 +0000 (02:20 +0100)
committerErwin Janssen <erwinjanssen@outlook.com>
Wed, 7 Dec 2016 13:52:40 +0000 (14:52 +0100)
When the local variables in the function `convert_edge_labels_to_nodes` in
lib/spare/DotIO.c are initialized, the pointer `g` is dereferenced. But a
the check that tests if `g` is NULL happens after this initialization. The
fix is placing the `if (!g) return NULL` as the first line of the
function, so dereferencing only occurs if the pointer is not NULL.

lib/sparse/DotIO.c

index 3b2da494ffb3305c288173d8f1a907405d6c4522..6e89c5c4143ca75de723d68dd209deb287dbb9d5 100644 (file)
@@ -676,6 +676,8 @@ char *cat_string3(char *s1, char *s2, char *s3, int id){
 
 
 Agraph_t *convert_edge_labels_to_nodes(Agraph_t* g){
+  if (!g) return NULL;
+
   Agnode_t *n, *newnode;
   Agraph_t *dg;
 
@@ -694,7 +696,6 @@ Agraph_t *convert_edge_labels_to_nodes(Agraph_t* g){
 
   dg = agopen("test", g->desc, 0);
 
-  if (!g) return NULL;
   nnodes = agnnodes (g);
   nedges = agnedges (g);