From a02044a3b9a44e24699311ed753491ebca472c62 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Fri, 24 Mar 2017 10:59:15 +0100 Subject: ipcpd: normal: Fix segfault in dijkstra calculation This fixes a dumb segfault in the dijkstra calculation. If an entry can be removed from the table it was set to NULL. However, if the table is completely empty, the index was -1, resulting in an illegal access into the table. --- src/ipcpd/normal/graph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c index 2ae36918..ed545b8c 100644 --- a/src/ipcpd/normal/graph.c +++ b/src/ipcpd/normal/graph.c @@ -340,7 +340,8 @@ static int get_min_vertex(struct vertex ** vertices, } } - vertices[index] = NULL; + if (index != -1) + vertices[index] = NULL; return index; } -- cgit v1.2.3 From 81a70d5ed630cad01b5a47a56b96c4d7bfe08765 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Fri, 24 Mar 2017 11:11:47 +0100 Subject: ipcpd: normal: Fix while loop The next vertex was not taken at the end of the Dijkstra calculation loop. --- src/ipcpd/normal/graph.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c index ed545b8c..ecaff14c 100644 --- a/src/ipcpd/normal/graph.c +++ b/src/ipcpd/normal/graph.c @@ -396,6 +396,7 @@ static struct vertex ** dijkstra(struct graph * graph, if (prev == NULL) return NULL; + /* Init the data structures */ list_for_each(p, &graph->vertices) { v = list_entry(p, struct vertex, next); vertices[i] = v; @@ -407,6 +408,7 @@ static struct vertex ** dijkstra(struct graph * graph, i++; } + /* Perform actual Dijkstra */ i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); while (v != NULL) { list_for_each(p, &v->edges) { @@ -429,6 +431,7 @@ static struct vertex ** dijkstra(struct graph * graph, prev[j] = v; } } + i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); } return prev; @@ -463,6 +466,10 @@ ssize_t graph_routing_table(struct graph * graph, return -1; } + /* + * Now loop through the list of predecessors + * to construct the routing table + */ list_for_each(p, &graph->vertices) { v = list_entry(p, struct vertex, next); prev = prevs[i]; -- cgit v1.2.3