From b626755dbcbbd6e464e780e2851b0685af170eaf Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sun, 21 Jul 2013 22:08:05 +0100 Subject: [PATCH] Fix segfault when IPv6 client is used (RHBZ#986601). --- ...is-not-large-enough-to-store-a-gener.patch | 58 +++++++++++++++++++ nbdkit.spec | 10 +++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 0001-struct-sockaddr-is-not-large-enough-to-store-a-gener.patch diff --git a/0001-struct-sockaddr-is-not-large-enough-to-store-a-gener.patch b/0001-struct-sockaddr-is-not-large-enough-to-store-a-gener.patch new file mode 100644 index 0000000..1a74ccb --- /dev/null +++ b/0001-struct-sockaddr-is-not-large-enough-to-store-a-gener.patch @@ -0,0 +1,58 @@ +From 49c5ff9ad0316960f11b180715b3a6906d42be83 Mon Sep 17 00:00:00 2001 +From: Michael Scherer +Date: Sun, 21 Jul 2013 21:59:28 +0100 +Subject: [PATCH] 'struct sockaddr' is not large enough to store a general + sockaddr. + +In particular, if IPv6 is used, then sizeof sockaddr_in6 > sizeof sockaddr, +resulting in a segfault: + +https://bugzilla.redhat.com/show_bug.cgi?id=986601 + +RWMJ: + - Minor formatting + - Free tls->addr on normal exit path +--- + src/tls.c | 12 +++++++++--- + 1 file changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/tls.c b/src/tls.c +index 08e8638..390b03e 100644 +--- a/src/tls.c ++++ b/src/tls.c +@@ -54,7 +54,7 @@ + struct tls { + const char *name; /* Can be NULL. */ + size_t instance_num; /* Can be 0. */ +- struct sockaddr addr; ++ struct sockaddr *addr; + socklen_t addrlen; + }; + +@@ -65,6 +65,7 @@ free_tls (void *tlsv) + { + struct tls *tls = tlsv; + ++ free (tls->addr); + free (tls); + } + +@@ -118,8 +119,13 @@ tls_set_sockaddr (struct sockaddr *addr, socklen_t addrlen) + struct tls *tls = pthread_getspecific (tls_key); + + if (tls) { +- tls->addrlen = addrlen; +- memcpy (&tls->addr, addr, addrlen); ++ free(tls->addr); ++ tls->addr = calloc (1, addrlen); ++ if (tls->addr == NULL) { ++ perror ("calloc"); ++ exit (EXIT_FAILURE); ++ } ++ memcpy(tls->addr, addr, addrlen); + } + } + +-- +1.8.3.1 + diff --git a/nbdkit.spec b/nbdkit.spec index 86bd254..a79933c 100644 --- a/nbdkit.spec +++ b/nbdkit.spec @@ -2,13 +2,17 @@ Name: nbdkit Version: 1.1.2 -Release: 2%{?dist} +Release: 3%{?dist} Summary: NBD server License: BSD URL: https://github.com/libguestfs/nbdkit Source0: http://libguestfs.org/download/nbdkit/%{name}-%{version}.tar.gz +# Fix segfault when IPv6 client is used (RHBZ#986601). +# Patch is upstream. +Patch1: 0001-struct-sockaddr-is-not-large-enough-to-store-a-gener.patch + BuildRequires: /usr/bin/pod2man BuildRequires: libguestfs-devel BuildRequires: libvirt-devel @@ -121,6 +125,7 @@ plugins for %{name}. %prep %setup -q +%patch1 -p1 %build @@ -199,6 +204,9 @@ make check %changelog +* Sun Jul 21 2013 Richard W.M. Jones - 1.1.2-3 +- Fix segfault when IPv6 client is used (RHBZ#986601). + * Tue Jul 16 2013 Richard W.M. Jones - 1.1.2-2 - New development version 1.1.2. - Disable the tests on Fedora <= 18.