From 8d86ae9f90ad6999dd7e5df5e876fcacbeba8553 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 11 Jul 2023 07:44:20 -0700 Subject: [PATCH] QNetworkInterface/Linux: fix mismatch of pointer and pointee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was hard to see the problem because of the lambda, combined with reinterpret_cast on the output of non-typesafe C macro. NLMSG_DATA returns a void*, so use static_cast to be sure not to do something wrong. This only affected the code that dealt with unexpected replies from the Linux kernel, which it doesn't send. So I don't expect this fixes any improper QNetworkInterface behavior. Found by CodeChecker. Change-Id: I61b74deaf2514644a24efffd1770d75e5a4f2636 Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 5bcacdbd1aa237cb3d39ffafbe378688a00ea502) Reviewed-by: Qt Cherry-pick Bot --- src/network/kernel/qnetworkinterface_linux.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/network/kernel/qnetworkinterface_linux.cpp b/src/network/kernel/qnetworkinterface_linux.cpp index 622cd2976b2..67ed8006bb7 100644 --- a/src/network/kernel/qnetworkinterface_linux.cpp +++ b/src/network/kernel/qnetworkinterface_linux.cpp @@ -111,7 +111,10 @@ struct NetlinkSocket template struct ProcessNetlinkRequest { using FunctionTraits = QtPrivate::FunctionPointer; - using FirstArgument = typename FunctionTraits::Arguments::Car; + using FirstArgumentPointer = typename FunctionTraits::Arguments::Car; + using FirstArgument = std::remove_pointer_t; + static_assert(std::is_pointer_v); + static_assert(std::is_aggregate_v); static int expectedTypeForRequest(int rtype) { @@ -136,7 +139,7 @@ template struct ProcessNetlinkRequest if (!NLMSG_OK(hdr, quint32(len))) return; - auto arg = reinterpret_cast(NLMSG_DATA(hdr)); + auto arg = static_cast(NLMSG_DATA(hdr)); size_t payloadLen = NLMSG_PAYLOAD(hdr, 0); // is this a multipart message? @@ -156,7 +159,7 @@ template struct ProcessNetlinkRequest // NLMSG_NEXT also updates the len variable hdr = NLMSG_NEXT(hdr, len); - arg = reinterpret_cast(NLMSG_DATA(hdr)); + arg = static_cast(NLMSG_DATA(hdr)); payloadLen = NLMSG_PAYLOAD(hdr, 0); } while (NLMSG_OK(hdr, quint32(len)));