Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent heap-use-after-free and make additional checks which prevent memory leak #94

Open
wants to merge 3 commits into
base: 1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,21 @@ void free_edge(edge_t *e) {
}

void edge_add(edge_t *e) {
splay_insert(edge_weight_tree, e);
splay_insert(e->from->edge_tree, e);

e->reverse = lookup_edge(e->to, e->from);

if(e->reverse)
e->reverse->reverse = e;
if (splay_insert(e->from->edge_tree, e)) {
e->reverse = lookup_edge(e->to, e->from);

if(e->reverse)
e->reverse->reverse = e;

if (!splay_insert(edge_weight_tree, e))
logger(DEBUG_ALWAYS, LOG_ERR,
"%s:%d: edge from: %s to: %s exists in edge_weight_tree",
__FUNCTION__, __LINE__, e->from->name, e->to->name);
} else {
logger(DEBUG_ALWAYS, LOG_ERR,
"%s:%d: edge from: %s to: %s exists in e->from->edge_tree",
__FUNCTION__, __LINE__, e->from->name, e->to->name);
}
}

void edge_del(edge_t *e) {
Expand Down
9 changes: 8 additions & 1 deletion src/protocol_edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ bool add_edge_h(connection_t *c, const char *request) {
// Otherwise, just ignore it.
sockaddrfree(&local_address);
return true;
} else if(local_address.sa.sa_family) {
} else if(local_address.sa.sa_family && local_address.sa.sa_family != AF_UNKNOWN) {
// We learned a new local address for this edge.
// local_address.sa.sa_family will be 0 if we got it from older tinc versions
// local_address.sa.sa_family will be 255 (AF_UNKNOWN) if we got it from newer versions
// but for edge which does not have local_address
sockaddrfree(&e->local_address);
e->local_address = local_address;

Expand All @@ -168,6 +171,10 @@ bool add_edge_h(connection_t *c, const char *request) {
forward_request(c, request);

return true;
} else {
logger(DEBUG_PROTOCOL, LOG_WARNING, "%s:%d %s -> %s - got edge we know from older version? (%d.%d)",
__FUNCTION__, __LINE__, e->from->name, e->to->name, c->protocol_major, c->protocol_minor);
return true;
}
} else {
sockaddrfree(&local_address);
Expand Down