From: Guus Sliepen Date: Wed, 10 Jun 2015 21:42:17 +0000 (+0200) Subject: Fix crash is sptps_logger(). X-Git-Tag: release-1.1pre12~121 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=45a46f068cf8fbe6cc8c59673de2d8580d18f87f;p=oweals%2Ftinc.git Fix crash is sptps_logger(). Unfortunately, sptps_logger() cannot know if s->handle is pointing to a connection_t or a node_t. But it needs to print name and hostname in both cases. So make sure both types have name and hostname fields at the start with the same offset. --- diff --git a/src/connection.h b/src/connection.h index b41cf46..7fa769f 100644 --- a/src/connection.h +++ b/src/connection.h @@ -59,9 +59,9 @@ typedef struct connection_status_t { typedef struct connection_t { char *name; /* name he claims to have */ + char *hostname; /* the hostname of its real ip */ union sockaddr_t address; /* his real (internet) ip */ - char *hostname; /* the hostname of its real ip */ int protocol_major; /* used protocol */ int protocol_minor; /* used protocol */ diff --git a/src/logger.c b/src/logger.c index ad7cef2..68a7fb2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -127,6 +127,8 @@ static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap if(message[len - 1] == '\n') message[--len] = 0; + // WARNING: s->handle can point to a connection_t or a node_t, + // but both types have the name and hostname fields at the same offsets. connection_t *c = s->handle; if(c) snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname); diff --git a/src/node.h b/src/node.h index 0800337..02e2a6d 100644 --- a/src/node.h +++ b/src/node.h @@ -45,12 +45,12 @@ typedef struct node_status_t { typedef struct node_t { char *name; /* name of this node */ + char *hostname; /* the hostname of its real ip */ node_id_t id; /* unique node ID (name hash) */ uint32_t options; /* options turned on for this node */ int sock; /* Socket to use for outgoing UDP packets */ sockaddr_t address; /* his real (internet) ip to send UDP packets to */ - char *hostname; /* the hostname of its real ip */ node_status_t status; time_t last_state_change;