QNetworkInterface/Linux: fix mismatch of pointer and pointee
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. Pick-to: 6.5 6.6 Change-Id: I61b74deaf2514644a24efffd1770d75e5a4f2636 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
536a4299be
commit
5bcacdbd1a
|
|
@ -111,7 +111,10 @@ struct NetlinkSocket
|
|||
template <typename Lambda> struct ProcessNetlinkRequest
|
||||
{
|
||||
using FunctionTraits = QtPrivate::FunctionPointer<decltype(&Lambda::operator())>;
|
||||
using FirstArgument = typename FunctionTraits::Arguments::Car;
|
||||
using FirstArgumentPointer = typename FunctionTraits::Arguments::Car;
|
||||
using FirstArgument = std::remove_pointer_t<FirstArgumentPointer>;
|
||||
static_assert(std::is_pointer_v<FirstArgumentPointer>);
|
||||
static_assert(std::is_aggregate_v<FirstArgument>);
|
||||
|
||||
static int expectedTypeForRequest(int rtype)
|
||||
{
|
||||
|
|
@ -136,7 +139,7 @@ template <typename Lambda> struct ProcessNetlinkRequest
|
|||
if (!NLMSG_OK(hdr, quint32(len)))
|
||||
return;
|
||||
|
||||
auto arg = reinterpret_cast<FirstArgument>(NLMSG_DATA(hdr));
|
||||
auto arg = static_cast<FirstArgument *>(NLMSG_DATA(hdr));
|
||||
size_t payloadLen = NLMSG_PAYLOAD(hdr, 0);
|
||||
|
||||
// is this a multipart message?
|
||||
|
|
@ -156,7 +159,7 @@ template <typename Lambda> struct ProcessNetlinkRequest
|
|||
|
||||
// NLMSG_NEXT also updates the len variable
|
||||
hdr = NLMSG_NEXT(hdr, len);
|
||||
arg = reinterpret_cast<FirstArgument>(NLMSG_DATA(hdr));
|
||||
arg = static_cast<FirstArgument *>(NLMSG_DATA(hdr));
|
||||
payloadLen = NLMSG_PAYLOAD(hdr, 0);
|
||||
} while (NLMSG_OK(hdr, quint32(len)));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue