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. Change-Id: I61b74deaf2514644a24efffd1770d75e5a4f2636 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 5bcacdbd1aa237cb3d39ffafbe378688a00ea502) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ae6e27d601
commit
8d86ae9f90
@ -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…
x
Reference in New Issue
Block a user