summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
authorPasi Petäjäjärvi <pasi.petajajarvi@qt.io>2022-02-22 17:11:52 +0200
committerThiago Macieira <thiago.macieira@intel.com>2022-02-24 07:49:10 +0000
commitdf270368eef9ccc357f9fea3c51a8152bdecb2d6 (patch)
treea0fa990f3d3999f2c5f4e9eb87dd62a44be307f3 /src/network/socket
parent708eb85e38acbe6c7aea4b95d92a9090f38375c9 (diff)
Fix getsockopt option_value initial initialization
On some platforms, some of the options we're getting the value for may be a single byte, so attempting to read the full int produces garbage. Found with IP_MULTICAST_TTL and IP_MULTICAST_LOOP on QNX. See: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.lib_ref/topic/g/getsockopt.html#getsockopt__IP_MULTICAST_TTL Pick-to: 5.15 6.2 6.3 Change-Id: Id9f7f249c6c4be0c3f94c5904d402b4ec4e17b59 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index e6704a3ca4..61fa8edbe9 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -46,6 +46,7 @@
#include "qelapsedtimer.h"
#include "qvarlengtharray.h"
#include "qnetworkinterface.h"
+#include "qendian.h"
#include <time.h>
#include <errno.h>
#include <fcntl.h>
@@ -329,12 +330,12 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co
}
int n, level;
- int v = -1;
+ int v = 0;
QT_SOCKOPTLEN_T len = sizeof(v);
convertToLevelAndOption(opt, socketProtocol, level, n);
if (n != -1 && ::getsockopt(socketDescriptor, level, n, (char *) &v, &len) != -1)
- return v;
+ return len == 1 ? qFromUnaligned<quint8>(&v) : v;
return -1;
}