Skip to content

Commit

Permalink
Don't send stuff to blacklisted nodes.
Browse files Browse the repository at this point in the history
The internal blacklist was only used on reception, which is okay
since it's supposed to trigger very seldom.  If we're ever going
to use it for other purposes, we should make it more general.
  • Loading branch information
Juliusz Chroboczek committed Jul 25, 2011
1 parent bf31e6b commit 2f8ab30
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dht.c
Original file line number Diff line number Diff line change
Expand Up @@ -1364,10 +1364,8 @@ node_blacklisted(const struct sockaddr *sa, int salen)
{
int i;

if(salen > sizeof(struct sockaddr_storage)) {
debugf("Checking for overlong blacklisted node.\n");
return -1;
}
if(salen > sizeof(struct sockaddr_storage))
abort();

for(i = 0; i < DHT_MAX_BLACKLISTED; i++) {
if(memcmp(&blacklist[i], sa, salen) == 0)
Expand Down Expand Up @@ -2312,6 +2310,12 @@ dht_send(const void *buf, size_t len, int flags,
if(salen == 0)
abort();

if(node_blacklisted(sa, salen)) {
debugf("Attempting to send to blacklisted node.\n");
errno = EPERM;
return -1;
}

if(sa->sa_family == AF_INET)
s = dht_socket;
else if(sa->sa_family == AF_INET6)
Expand Down

0 comments on commit 2f8ab30

Please sign in to comment.