diff options
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index c8d9919ea..3290abcfc 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -828,13 +828,22 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
828 | #ifdef AF_UNIX | 828 | #ifdef AF_UNIX |
829 | struct GNUNET_CONNECTION_Handle *connection; | 829 | struct GNUNET_CONNECTION_Handle *connection; |
830 | struct sockaddr_un *un; | 830 | struct sockaddr_un *un; |
831 | size_t slen; | ||
831 | 832 | ||
832 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 833 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
833 | un = GNUNET_new (struct sockaddr_un); | 834 | un = GNUNET_new (struct sockaddr_un); |
834 | un->sun_family = AF_UNIX; | 835 | un->sun_family = AF_UNIX; |
835 | strncpy(un->sun_path, unixpath, sizeof(un->sun_path) - 1); | 836 | slen = strlen (unixpath); |
837 | if (slen >= sizeof (un->sun_path)) | ||
838 | slen = sizeof (un->sun_path) - 1; | ||
839 | memcpy (un->sun_path, unixpath, slen); | ||
840 | un->sun_path[slen] = '\0'; | ||
841 | slen = sizeof (struct sockaddr_un); | ||
836 | #if HAVE_SOCKADDR_IN_SIN_LEN | 842 | #if HAVE_SOCKADDR_IN_SIN_LEN |
837 | un->sun_len = (u_char) sizeof (struct sockaddr_un); | 843 | un->sun_len = (u_char) slen; |
844 | #endif | ||
845 | #if LINUX | ||
846 | un->sun_path[0] = '\0'; | ||
838 | #endif | 847 | #endif |
839 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); | 848 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); |
840 | connection->cfg = cfg; | 849 | connection->cfg = cfg; |
@@ -843,7 +852,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
843 | connection->port = 0; | 852 | connection->port = 0; |
844 | connection->hostname = NULL; | 853 | connection->hostname = NULL; |
845 | connection->addr = (struct sockaddr *) un; | 854 | connection->addr = (struct sockaddr *) un; |
846 | connection->addrlen = sizeof (struct sockaddr_un); | 855 | connection->addrlen = slen; |
847 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 856 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
848 | if (NULL == connection->sock) | 857 | if (NULL == connection->sock) |
849 | { | 858 | { |