From 002641dca1067843c94349c3bd7cf4ee0afcae37 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 2 May 2012 13:25:32 +0000 Subject: [PATCH] - fix --- src/transport/plugin_transport_udp.c | 23 ++++++++++++++++++++++- src/transport/plugin_transport_unix.c | 20 +++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index b1da80431..9e28f00d4 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -380,11 +380,30 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, void **buf, size_t *added) { struct sockaddr_storage socket_address; - int ret = GNUNET_STRINGS_to_address_ip (addr, addrlen, + + if ((NULL == addr) || (addrlen == 0)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + + if ('\0' != addr[addrlen - 1]) + { + return GNUNET_SYSERR; + } + + if (strlen (addr) != addrlen - 1) + { + return GNUNET_SYSERR; + } + + int ret = GNUNET_STRINGS_to_address_ip (addr, strlen (addr), &socket_address); if (ret != GNUNET_OK) + { return GNUNET_SYSERR; + } if (socket_address.ss_family == AF_INET) { @@ -395,6 +414,7 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, u4->u4_port = in4->sin_port; *buf = u4; *added = sizeof (struct IPv4UdpAddress); + return GNUNET_OK; } else if (socket_address.ss_family == AF_INET6) { @@ -405,6 +425,7 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, u6->u6_port = in6->sin6_port; *buf = u6; *added = sizeof (struct IPv6UdpAddress); + return GNUNET_OK; } return GNUNET_SYSERR; } diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 9c29aeb14..78025ab75 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -1041,7 +1041,7 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, * * @param cls closure ('struct Plugin*') * @param addr string address - * @param addrlen length of the address + * @param addrlen length of the address (strlen(addr) + '\0') * @param buf location to store the buffer * If the function returns GNUNET_SYSERR, its contents are undefined. * @param added length of created address @@ -1057,14 +1057,20 @@ unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, return GNUNET_SYSERR; } - char * tmp = GNUNET_malloc (addrlen + 1); - memcpy (tmp, addr, addrlen); - tmp[addrlen] = '\0'; + if ('\0' != addr[addrlen - 1]) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "`%s'\n", tmp); + if (strlen (addr) != addrlen - 1) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } - (*buf) = tmp; - (*added) = strlen (tmp) + 1; + (*buf) = strdup (addr); + (*added) = strlen (addr) + 1; return GNUNET_OK; } -- 2.25.1