aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-06-07 11:34:55 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-06-07 15:14:13 +0000
commit5ce475e78e8ee8e18bf2436bc2f3f1996ee4bfc2 (patch)
treec944fcb6ae842c483ac8b852d645c5cd00653802
parent577ee1cc427308e42a8ff0289ca2500e18f0217e (diff)
Fix parsing of option values
When parsing the CoAP option values, pointers to temporary QByteArray data were used, which could lead to parsing garbage instead of the option value. So far this stayed undetected, when compiling with most of the compilers, except for MSVC. Change-Id: I4751b514dee008d9186306857f3d6737547f31fb Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/coap/qcoapinternalmessage.cpp3
-rw-r--r--src/coap/qcoapinternalreply.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/coap/qcoapinternalmessage.cpp b/src/coap/qcoapinternalmessage.cpp
index 271ab30..59f63ba 100644
--- a/src/coap/qcoapinternalmessage.cpp
+++ b/src/coap/qcoapinternalmessage.cpp
@@ -123,7 +123,8 @@ void QCoapInternalMessage::setFromDescriptiveBlockOption(const QCoapOption &opti
{
Q_D(QCoapInternalMessage);
- const quint8 *optionData = reinterpret_cast<const quint8 *>(option.opaqueValue().data());
+ const auto value = option.opaqueValue();
+ const quint8 *optionData = reinterpret_cast<const quint8 *>(value.data());
const quint8 lastByte = optionData[option.length() - 1];
quint32 blockNumber = 0;
diff --git a/src/coap/qcoapinternalreply.cpp b/src/coap/qcoapinternalreply.cpp
index 2480a05..b795046 100644
--- a/src/coap/qcoapinternalreply.cpp
+++ b/src/coap/qcoapinternalreply.cpp
@@ -188,7 +188,8 @@ int QCoapInternalReply::nextBlockToSend() const
if (!option.isValid())
return -1;
- const quint8 *optionData = reinterpret_cast<const quint8 *>(option.opaqueValue().data());
+ const auto value = option.opaqueValue();
+ const quint8 *optionData = reinterpret_cast<const quint8 *>(value.data());
const quint8 lastByte = optionData[option.length() - 1];
// M field