diff options
| author | Pasi Petäjäjärvi <[email protected]> | 2022-02-22 17:11:52 +0200 | 
|---|---|---|
| committer | Thiago Macieira <[email protected]> | 2022-02-24 07:49:10 +0000 | 
| commit | df270368eef9ccc357f9fea3c51a8152bdecb2d6 (patch) | |
| tree | a0fa990f3d3999f2c5f4e9eb87dd62a44be307f3 /src | |
| parent | 708eb85e38acbe6c7aea4b95d92a9090f38375c9 (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 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/network/socket/qnativesocketengine_unix.cpp | 5 | 
1 files changed, 3 insertions, 2 deletions
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index e6704a3ca44..61fa8edbe91 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;  }  | 
