Skip to content

Commit 6c654ad

Browse files
committed
prevent use-after-free in local printing if dumping immediately after flushing interface.
updating comment. flushing neighbours associated with flushed interface. flushing neighbours associated with flushed interface.
1 parent 950992f commit 6c654ad

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

interface.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int
101101
flush_interface(char *ifname)
102102
{
103103
struct interface *ifp, *prev;
104+
struct neighbour *neigh;
104105

105106
prev = NULL;
106107
ifp = interfaces;
@@ -114,6 +115,18 @@ flush_interface(char *ifname)
114115
if(ifp == NULL)
115116
return 0;
116117

118+
/* flush any neighbours associated with interface */
119+
neigh = neighs;
120+
while(neigh) {
121+
if(neigh->ifp == ifp) {
122+
struct neighbour *old = neigh;
123+
neigh = neigh->next;
124+
flush_neighbour(old);
125+
continue;
126+
}
127+
neigh = neigh->next;
128+
}
129+
117130
interface_updown(ifp, 0);
118131
if(prev)
119132
prev->next = ifp->next;

neighbour.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
5454
return NULL;
5555
}
5656

57-
static void
57+
void
5858
flush_neighbour(struct neighbour *neigh)
5959
{
6060
flush_neighbour_routes(neigh);

neighbour.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct neighbour *find_neighbour(const unsigned char *address,
6868
int update_neighbour(struct neighbour *neigh, struct hello_history *hist,
6969
int unicast, int hello, int hello_interval);
7070
unsigned check_neighbours(void);
71+
void flush_neighbour(struct neighbour *neigh);
7172
unsigned neighbour_txcost(struct neighbour *neigh);
7273
unsigned neighbour_rxcost(struct neighbour *neigh);
7374
unsigned neighbour_rttcost(struct neighbour *neigh);

0 commit comments

Comments
 (0)