Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Dec 2018 16:46:17 +0000 (UTC)
From:      Adriaan de Groot <adridg@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r488276 - in head/net/qt5-network: . files
Message-ID:  <201812241646.wBOGkHMX080069@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adridg
Date: Mon Dec 24 16:46:16 2018
New Revision: 488276
URL: https://svnweb.freebsd.org/changeset/ports/488276

Log:
  Fix net/qt5-network in the face of VLANs.
  
  Adding a VLAN to a FreeBSD system caused memory corruption -- usually
  enough to make rtld fall over with symbol resolution errors, although
  in DEBUG builds it would just crash. Revamp network interface discovery
  to not be full of memory gotcha's.
  
  An explanation is included in the patches. While here, "make makesum"
  has moved some files around.
  
  PR:		231402, 233798, 232318
  Reported by:	Ting-Wei Lan, Nils Beyer, Marek Zarychta

Added:
  head/net/qt5-network/files/patch-src_network_socket_qnet__unix__p.h   (contents, props changed)
  head/net/qt5-network/files/patch-src_network_ssl_qsslcontext__openssl.cpp   (contents, props changed)
  head/net/qt5-network/files/patch-src_plugins_bearer_generic_qgenericengine.cpp   (contents, props changed)
Deleted:
  head/net/qt5-network/files/patch-qsslcontext_openssl.cpp
  head/net/qt5-network/files/patch-src_network_socket_qnet_unix_p.h
Modified:
  head/net/qt5-network/Makefile
  head/net/qt5-network/files/patch-src_network_kernel_qnetworkinterface__unix.cpp

Modified: head/net/qt5-network/Makefile
==============================================================================
--- head/net/qt5-network/Makefile	Mon Dec 24 16:09:43 2018	(r488275)
+++ head/net/qt5-network/Makefile	Mon Dec 24 16:46:16 2018	(r488276)
@@ -2,6 +2,7 @@
 
 PORTNAME=	network
 DISTVERSION=	${QT5_VERSION}
+PORTREVISION=	1
 CATEGORIES=	net ipv6
 PKGNAMEPREFIX=	qt5-
 

Modified: head/net/qt5-network/files/patch-src_network_kernel_qnetworkinterface__unix.cpp
==============================================================================
--- head/net/qt5-network/files/patch-src_network_kernel_qnetworkinterface__unix.cpp	Mon Dec 24 16:09:43 2018	(r488275)
+++ head/net/qt5-network/files/patch-src_network_kernel_qnetworkinterface__unix.cpp	Mon Dec 24 16:46:16 2018	(r488276)
@@ -1,12 +1,95 @@
---- src/network/kernel/qnetworkinterface_unix.cpp.orig	2018-06-15 07:29:31 UTC
+Clean up interface type and MTU detection.
+
+ - Introduce a class SockPuppet that handles closing the socket
+   automatically, and handles different address families as well.
+ - Finding MTU requires using AF_LOCAL, cribbed that detail from ifconfig.c
+ - Zero out structures more diligently, initialize pointers to nullptr.
+ - In particular, don't use a union of structs passed in to ioctl().
+   Make them separate structs (with block scope so the compiler might
+   place them on top of each other, that would be ok).
+
+--- src/network/kernel/qnetworkinterface_unix.cpp.orig	2018-12-24 17:00:42 UTC
 +++ src/network/kernel/qnetworkinterface_unix.cpp
-@@ -463,9 +463,6 @@ static QNetworkInterface::InterfaceType probeIfType(in
-         case IFM_ETHER:
-             return QNetworkInterface::Ethernet;
+@@ -419,12 +419,23 @@ QT_BEGIN_INCLUDE_NAMESPACE
+ #endif // QT_PLATFORM_UIKIT
+ QT_END_INCLUDE_NAMESPACE
  
--        case IFM_FDDI:
--            return QNetworkInterface::Fddi;
+-static int openSocket(int &socket)
++template<int address_family> struct SockPuppet
+ {
+-    if (socket == -1)
+-        socket = qt_safe_socket(AF_INET, SOCK_DGRAM, 0);
+-    return socket;
+-}
++    int socket{-1};
++
++    int open() 
++    {
++        if (socket == -1)
++            socket = qt_safe_socket(address_family, SOCK_DGRAM, 0);
++        return socket;
++    }
++
++    ~SockPuppet()
++    {
++        if (socket != -1)
++            qt_safe_close(socket);
++    }
++} ;
+ 
+ static QNetworkInterface::InterfaceType probeIfType(int socket, int iftype, struct ifmediareq *req)
+ {
+@@ -477,15 +488,8 @@ static QNetworkInterface::InterfaceType 
+ static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList)
+ {
+     QList<QNetworkInterfacePrivate *> interfaces;
+-    union {
+-        struct ifmediareq mediareq;
+-        struct ifreq req;
+-    };
+-    int socket = -1;
 -
-         case IFM_IEEE80211:
-             return QNetworkInterface::Ieee80211;
+-    // ensure both structs start with the name field, of size IFNAMESIZ
+-    Q_STATIC_ASSERT(sizeof(mediareq.ifm_name) == sizeof(req.ifr_name));
+-    Q_ASSERT(&mediareq.ifm_name == &req.ifr_name);
++    SockPuppet<AF_INET> socket;
++    SockPuppet<AF_LOCAL> localSocket;
+ 
+     // on NetBSD we use AF_LINK and sockaddr_dl
+     // scan the list for that family
+@@ -500,13 +504,21 @@ static QList<QNetworkInterfacePrivate *>
+             iface->flags = convertFlags(ptr->ifa_flags);
+             iface->hardwareAddress = iface->makeHwAddress(sdl->sdl_alen, (uchar*)LLADDR(sdl));
+ 
+-            strlcpy(mediareq.ifm_name, ptr->ifa_name, sizeof(mediareq.ifm_name));
+-            iface->type = probeIfType(openSocket(socket), sdl->sdl_type, &mediareq);
+-            iface->mtu = getMtu(socket, &req);
++            {
++                ifmediareq req;
++                memset(&req, 0, sizeof(req));
++                strncpy(req.ifm_name, ptr->ifa_name, sizeof(req.ifm_name));
++                iface->type = probeIfType(socket.open(), sdl->sdl_type, &req);
++            }
++            {
++                ifreq req;
++                memset(&req, 0, sizeof(req));
++                strncpy(req.ifr_name, ptr->ifa_name, sizeof(req.ifr_name));
++                req.ifr_addr.sa_family = AF_LOCAL;
++                iface->mtu = getMtu(localSocket.open(), &req);
++            }
          }
+ 
+-    if (socket != -1)
+-        qt_safe_close(socket);
+     return interfaces;
+ }
+ 
+@@ -605,7 +617,7 @@ static QList<QNetworkInterfacePrivate *>
+ {
+     QList<QNetworkInterfacePrivate *> interfaces;
+ 
+-    ifaddrs *interfaceListing;
++    ifaddrs *interfaceListing = nullptr;
+     if (getifaddrs(&interfaceListing) == -1) {
+         // error
+         return interfaces;

Added: head/net/qt5-network/files/patch-src_network_socket_qnet__unix__p.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/qt5-network/files/patch-src_network_socket_qnet__unix__p.h	Mon Dec 24 16:46:16 2018	(r488276)
@@ -0,0 +1,17 @@
+Some extra includes for us.
+
+--- src/network/socket/qnet_unix_p.h.orig	2018-12-03 11:15:26 UTC
++++ src/network/socket/qnet_unix_p.h
+@@ -71,6 +71,12 @@
+ #  include <resolv.h>
+ #endif
+ 
++#if defined(Q_OS_FREEBSD)
++#  include <net/if.h>
++#  include <net/if_types.h>
++#  include <net/if_var.h>
++#endif 
++
+ QT_BEGIN_NAMESPACE
+ 
+ // Almost always the same. If not, specify in qplatformdefs.h.

Added: head/net/qt5-network/files/patch-src_network_ssl_qsslcontext__openssl.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/qt5-network/files/patch-src_network_ssl_qsslcontext__openssl.cpp	Mon Dec 24 16:46:16 2018	(r488276)
@@ -0,0 +1,15 @@
+* 
+* Fix for libressl after openssl111 API change
+*
+*
+--- src/network/ssl/qsslcontext_openssl.cpp.orig	2018-12-03 11:15:26 UTC
++++ src/network/ssl/qsslcontext_openssl.cpp
+@@ -249,7 +249,7 @@ void QSslContext::applyBackendConfig(QSs
+     if (sslContext->sslConfiguration.backendConfiguration().isEmpty())
+         return;
+ 
+-#if OPENSSL_VERSION_NUMBER >= 0x10002000L
++#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER)
+     if (QSslSocket::sslLibraryVersionNumber() >= 0x10002000L) {
+         QSharedPointer<SSL_CONF_CTX> cctx(q_SSL_CONF_CTX_new(), &q_SSL_CONF_CTX_free);
+         if (cctx) {

Added: head/net/qt5-network/files/patch-src_plugins_bearer_generic_qgenericengine.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/qt5-network/files/patch-src_plugins_bearer_generic_qgenericengine.cpp	Mon Dec 24 16:46:16 2018	(r488276)
@@ -0,0 +1,42 @@
+Determine suitable bearer. This code is basically the same
+as the Linux code, except out ioctl()s are named differently
+and we need an AF_LOCAL socket (this detail cribbed from ifconfig.c).
+If getting the HW address succeeds, assume it's Ethernet. Tested
+with two Ethernet cards and a vlan (all of which have a MAC reported
+by ifconfig).
+
+--- src/plugins/bearer/generic/qgenericengine.cpp.orig	2018-12-03 12:15:26.000000000 +0100
++++ src/plugins/bearer/generic/qgenericengine.cpp	2018-12-23 12:42:48.095145000 +0100
+@@ -82,7 +82,7 @@
+ // needed as interface is used as parameter name in qGetInterfaceType
+ #undef interface
+ 
+-#ifdef Q_OS_LINUX
++#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
+ #include <sys/socket.h>
+ #include <sys/ioctl.h>
+ #include <net/if.h>
+@@ -139,6 +139,23 @@
+ 
+     if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER)
+         return QNetworkConfiguration::BearerEthernet;
++
++#elif defined(Q_OS_FREEBSD)
++    int sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
++
++    ifreq request;
++    memset(&request, 0, sizeof(struct ifreq));
++    strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name) - 1);
++    request.ifr_name[sizeof(request.ifr_name) - 1] = '\0';
++
++    if (sock >= 0) {
++        int result = ioctl(sock, SIOCGHWADDR, &request);
++        close(sock);
++
++        if (result >= 0)
++            return QNetworkConfiguration::BearerEthernet;
++    }
++
+ #elif defined(Q_OS_WINRT)
+     ComPtr<INetworkInformationStatics> networkInfoStatics;
+     HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Connectivity_NetworkInformation).Get(), &networkInfoStatics);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812241646.wBOGkHMX080069>