Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package qt6-serialbus for openSUSE:Factory checked in at 2026-11-30 14:24:00 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/qt6-serialbus (Old) and /work/SRC/openSUSE:Factory/.qt6-serialbus.new.1340718 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "qt6-serialbus" Mon Nov 30 14:24:00 2026 rev:39 rq:1400923 version:6.12.1 Changes: -------- --- /work/SRC/openSUSE:Factory/qt6-serialbus/qt6-serialbus.changes 2026-10-18 19:21:51.298106041 +0200 +++ /work/SRC/openSUSE:Factory/.qt6-serialbus.new.1340718/qt6-serialbus.changes 2026-11-30 14:24:47.585865733 +0100 @@ -1,0 +2,6 @@ +Tue Nov 24 13:37:46 UTC 2026 - Christophe Marin <[email protected]> + +- Update to 6.12.1 + https://www.qt.io/blog/qt-6.12.1-released + +------------------------------------------------------------------- Old: ---- qtserialbus-everywhere-src-6.12.0.tar.xz New: ---- qtserialbus-everywhere-src-6.12.1.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ qt6-serialbus.spec ++++++ --- /var/tmp/diff_new_pack.ASiRLN/_old 2026-11-30 14:24:49.177933187 +0100 +++ /var/tmp/diff_new_pack.ASiRLN/_new 2026-11-30 14:24:49.179933272 +0100 @@ -16,7 +16,7 @@ # -%define real_version 6.12.0 +%define real_version 6.12.1 %define short_version 6.12 %define tar_name qtserialbus-everywhere-src %define tar_suffix %{nil} @@ -27,7 +27,7 @@ %endif # Name: qt6-serialbus -Version: 6.12.0 +Version: 6.12.1 Release: 0 Summary: Qt 6 SerialBus library License: GPL-2.0-or-later OR LGPL-3.0-only ++++++ qtserialbus-everywhere-src-6.12.0.tar.xz -> qtserialbus-everywhere-src-6.12.1.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/.cmake.conf new/qtserialbus-everywhere-src-6.12.1/.cmake.conf --- old/qtserialbus-everywhere-src-6.12.0/.cmake.conf 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/.cmake.conf 2026-11-16 17:43:49.000000000 +0100 @@ -1,4 +1,4 @@ -set(QT_REPO_MODULE_VERSION "6.12.0") +set(QT_REPO_MODULE_VERSION "6.12.1") set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_CONTEXTLESS_CONNECT=1" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/.tag new/qtserialbus-everywhere-src-6.12.1/.tag --- old/qtserialbus-everywhere-src-6.12.0/.tag 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/.tag 2026-11-16 17:43:49.000000000 +0100 @@ -1 +1 @@ -7e730085399effee86f0fdfa9e6cc650b5a09921 +a7ce697b8f37075ec85d6f69c85ea719b0dd139e diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/coin/axivion/ci_config_linux.json new/qtserialbus-everywhere-src-6.12.1/coin/axivion/ci_config_linux.json --- old/qtserialbus-everywhere-src-6.12.0/coin/axivion/ci_config_linux.json 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/coin/axivion/ci_config_linux.json 2026-11-16 17:43:49.000000000 +0100 @@ -28,7 +28,7 @@ ], "ir": "build/$(env:TESTED_MODULE_COIN).ir", "plugin_files": [ - "build/plugins/*/lib*.so*.ir" + "build/plugins/**/lib*.so*.ir" ] } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/dependencies.yaml new/qtserialbus-everywhere-src-6.12.1/dependencies.yaml --- old/qtserialbus-everywhere-src-6.12.0/dependencies.yaml 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/dependencies.yaml 2026-11-16 17:43:49.000000000 +0100 @@ -1,7 +1,7 @@ dependencies: ../qtbase: - ref: 025bdad181de241e81bf853c8a2d7bf3d19261a9 + ref: 5af1a37e31a869cd6eb8a73d82e2c71a450e6634 required: true ../qtserialport: - ref: beb4c887f3b886447cf86592fa65b8b9c1d6e312 + ref: 2f5b639dec585f26e47c83f969c6a870100e9b1d required: false diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/peakcan/peakcanbackend.cpp new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/peakcan/peakcanbackend.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/peakcan/peakcanbackend.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/peakcan/peakcanbackend.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -716,7 +716,12 @@ if (Q_UNLIKELY(message.MSGTYPE & PCAN_MESSAGE_STATUS)) continue; - const int size = dlcToSize(static_cast<CanFrameDlc>(message.DLC)); + if (Q_UNLIKELY(message.DLC > 15)) + continue; + + qsizetype size = std::min(qsizetype(message.DLC), qsizetype(8)); + if (message.MSGTYPE & PCAN_MESSAGE_FD) + size = dlcToSize(static_cast<CanFrameDlc>(message.DLC)); QCanBusFrame frame(message.ID, QByteArray(reinterpret_cast<const char *>(message.DATA), size)); frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(static_cast<qint64>(timestamp))); frame.setExtendedFrameFormat(message.MSGTYPE & PCAN_MESSAGE_EXTENDED); @@ -747,7 +752,8 @@ if (Q_UNLIKELY(message.MSGTYPE & PCAN_MESSAGE_STATUS)) continue; - const int size = static_cast<int>(message.LEN); + const qsizetype size = std::min(qsizetype(message.LEN), + qsizetype(sizeof(message.DATA))); QCanBusFrame frame(message.ID, QByteArray(reinterpret_cast<const char *>(message.DATA), size)); const quint64 millis = timestamp.millis + Q_UINT64_C(0x100000000) * timestamp.millis_overflow; const quint64 micros = Q_UINT64_C(1000) * millis + timestamp.micros; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/systeccan/systeccanbackend.cpp new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/systeccan/systeccanbackend.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/systeccan/systeccanbackend.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/systeccan/systeccanbackend.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -15,6 +15,8 @@ #include <QtCore/qregularexpression.h> #include <QtCore/qtimer.h> +#include <algorithm> + QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_CANBUS_PLUGINS_SYSTECCAN) @@ -386,9 +388,10 @@ break; } + const qsizetype dataSize = std::min(qsizetype(message.m_bDLC), + qsizetype(sizeof(message.m_bData))); QCanBusFrame frame(message.m_dwID, - QByteArray(reinterpret_cast<const char *>(message.m_bData), - int(message.m_bDLC))); + QByteArray(reinterpret_cast<const char *>(message.m_bData), dataSize)); // TODO: Timestamp can also be set to 100 us resolution with kUcanModeHighResTimer frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(message.m_dwTime * 1000)); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/tinycan/tinycanbackend.cpp new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/tinycan/tinycanbackend.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/tinycan/tinycanbackend.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/tinycan/tinycanbackend.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -366,8 +366,10 @@ continue; } + const qsizetype dataSize = std::min(qsizetype(message.Flags.Flag.Len), + qsizetype(sizeof(message.Data.Bytes))); QCanBusFrame frame(message.Id, QByteArray(reinterpret_cast<char *>(message.Data.Bytes), - int(message.Flags.Flag.Len))); + dataSize)); frame.setTimeStamp(QCanBusFrame::TimeStamp(message.Time.Sec, message.Time.USec)); frame.setExtendedFrameFormat(message.Flags.Flag.EFF); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/vectorcan/vectorcanbackend.cpp new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/vectorcan/vectorcanbackend.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/plugins/canbus/vectorcan/vectorcanbackend.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/plugins/canbus/vectorcan/vectorcanbackend.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -475,22 +475,31 @@ const XL_CAN_EV_RX_MSG &msg = event.tagData.canRxOkMsg; - int dataLength = msg.dlc; - switch (msg.dlc) { - case 9: dataLength = 12; break; - case 10: dataLength = 16; break; - case 11: dataLength = 20; break; - case 12: dataLength = 24; break; - case 13: dataLength = 32; break; - case 14: dataLength = 48; break; - case 15: dataLength = 64; break; + if (Q_UNLIKELY(msg.dlc > 15)) + continue; + + qsizetype dataLength = msg.dlc; + if (msg.flags & XL_CAN_RXMSG_FLAG_EDL) { + switch (msg.dlc) { + case 9: dataLength = 12; break; + case 10: dataLength = 16; break; + case 11: dataLength = 20; break; + case 12: dataLength = 24; break; + case 13: dataLength = 32; break; + case 14: dataLength = 48; break; + case 15: dataLength = 64; break; + } + } else { + dataLength = std::min(dataLength, qsizetype(8)); } QCanBusFrame frame(msg.id & ~XL_CAN_EXT_MSG_ID, QByteArray(reinterpret_cast<const char *>(msg.data), dataLength)); frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(event.timeStamp / 1000)); frame.setExtendedFrameFormat(msg.id & XL_CAN_EXT_MSG_ID); + frame.setFlexibleDataRateFormat(msg.flags & XL_CAN_RXMSG_FLAG_EDL); frame.setBitrateSwitch(msg.flags & XL_CAN_RXMSG_FLAG_BRS); + frame.setErrorStateIndicator(msg.flags & XL_CAN_RXMSG_FLAG_ESI); frame.setLocalEcho(isEchoFrame); frame.setFrameType((msg.flags & XL_CAN_RXMSG_FLAG_RTR) ? QCanBusFrame::RemoteRequestFrame @@ -518,8 +527,10 @@ if ((msg.flags & XL_CAN_MSG_FLAG_TX_COMPLETED) && !transmitEcho) continue; + const qsizetype dataSize = std::min(qsizetype(msg.dlc), + qsizetype(sizeof(msg.data))); QCanBusFrame frame(msg.id & ~XL_CAN_EXT_MSG_ID, - QByteArray(reinterpret_cast<const char *>(msg.data), int(msg.dlc))); + QByteArray(reinterpret_cast<const char *>(msg.data), dataSize)); frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(event.timeStamp / 1000)); frame.setExtendedFrameFormat(msg.id & XL_CAN_EXT_MSG_ID); frame.setLocalEcho(msg.flags & XL_CAN_MSG_FLAG_TX_COMPLETED); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanbus.cpp new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanbus.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanbus.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanbus.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -20,31 +20,34 @@ class QCanBusPrivate { public: - QCanBusPrivate() { } - QCanBusPrivate(int index, const QCborMap &meta) : meta(meta), index(index) {} - - QCborMap meta; QObject *factory = nullptr; - int index = -1; + QList<int> indexes; }; -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, qFactoryLoader, - (QCanBusFactory_iid, QLatin1String("/canbus"))) +namespace { +struct QCanBusLoader +{ + QCanBusLoader(); -typedef QMap<QString, QCanBusPrivate> QCanBusPluginStore; -Q_GLOBAL_STATIC(QCanBusPluginStore, qCanBusPlugins) + QFactoryLoader loader{QCanBusFactory_iid, QLatin1String("/canbus")}; + QMap<QString, QCanBusPrivate> store; +}; +} // unnamed namespace + +Q_GLOBAL_STATIC(QCanBusLoader, qCanBusLoader) static QCanBus *globalInstance = nullptr; -static void loadPlugins() +QCanBusLoader::QCanBusLoader() { - const QList<QPluginParsedMetaData> meta = qFactoryLoader()->metaData(); + const QList<QPluginParsedMetaData> meta = loader.metaData(); for (int i = 0; i < meta.size(); i++) { const QCborMap obj = meta.at(i).value(QtPluginMetaDataKeys::MetaData).toMap(); if (obj.isEmpty()) continue; - qCanBusPlugins()->insert(obj.value(QLatin1String("Key")).toString(), {i, obj}); + QCanBusPrivate &d = store[obj.value(QLatin1String("Key")).toString()]; + d.indexes.append(i); } } @@ -75,7 +78,7 @@ */ QStringList QCanBus::plugins() const { - return qCanBusPlugins()->keys(); + return qCanBusLoader()->store.keys(); } static void setErrorMessage(QString *result, const QString &message) @@ -88,17 +91,21 @@ static QObject *canBusFactory(const QString &plugin, QString *errorMessage) { - if (Q_UNLIKELY(!qCanBusPlugins()->contains(plugin))) { + QCanBusLoader *globals = qCanBusLoader(); + if (Q_UNLIKELY(!globals->store.contains(plugin))) { setErrorMessage(errorMessage, QCanBus::tr("No such plugin: '%1'").arg(plugin)); return nullptr; } - QCanBusPrivate d = qCanBusPlugins()->value(plugin); + QCanBusPrivate d = globals->store.value(plugin); if (!d.factory) { - d.factory = qFactoryLoader->instance(d.index); - - if (d.factory) - qCanBusPlugins()->insert(plugin, d); + for (int index : std::as_const(d.indexes)) { + d.factory = globals->loader.instance(index); + if (d.factory) { + globals->store.insert(plugin, d); + break; + } + } } if (Q_UNLIKELY(!d.factory)) @@ -215,7 +222,7 @@ QCanBus::QCanBus(QObject *parent) : QObject(parent) { - loadPlugins(); + qCanBusLoader(); // trigger plugin discovery } QT_END_NAMESPACE diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcandbcfileparser.cpp new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcandbcfileparser.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcandbcfileparser.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcandbcfileparser.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -13,6 +13,7 @@ #include <QtCore/QFile> #include <QtCore/QRegularExpression> +#include <limits> #include <optional> QT_BEGIN_NAMESPACE @@ -72,7 +73,7 @@ extracted message descriptions, error code, or warnings) are reset once the next parsing starts. - \section2 Supported Keywords + \section1 Supported Keywords The current implementation supports only a subset of keywords that you can find in a DBC file: @@ -570,7 +571,7 @@ bool ok = false; const auto size = match.capturedView(u"size"_s).toUInt(&ok); - if (ok) { + if (ok && size <= std::numeric_limits<quint8>::max()) { desc.setSize(size); } else { addWarning(QObject::tr("Failed to parse size for message %1").arg(desc.name())); @@ -675,7 +676,7 @@ } const uint startBit = match.capturedView(u"startBit"_s).toUInt(&ok); - if (ok) { + if (ok && startBit <= std::numeric_limits<quint16>::max()) { desc.setStartBit(startBit); } else { addWarning(QObject::tr("Failed to parse start bit for signal %1").arg(desc.name())); @@ -683,7 +684,7 @@ } const uint bitLength = match.capturedView(u"sigSize"_s).toUInt(&ok); - if (ok) { + if (ok && bitLength <= std::numeric_limits<quint16>::max()) { desc.setBitLength(bitLength); } else { addWarning(QObject::tr("Failed to parse bit length for signal %1").arg(desc.name())); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanframeprocessor.cpp new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanframeprocessor.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanframeprocessor.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanframeprocessor.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -28,7 +28,8 @@ // Helper method to extract the max bit number of the signal. // Note that for BE it's not the last bit of the signal. -static quint16 extractMaxBitNum(quint16 startBit, quint16 bitLength, QSysInfo::Endian endian) +// The two quint16 inputs can combine past their own width, so this result must not truncate. +static qsizetype extractMaxBitNum(quint16 startBit, quint16 bitLength, QSysInfo::Endian endian) { #ifdef USE_DBC_COMPATIBLE_BE_HANDLING if (endian == QSysInfo::Endian::LittleEndian) { @@ -684,7 +685,8 @@ // types, so we convert the value to uchar *. unsigned char *valueData = reinterpret_cast<unsigned char *>(&value); quint16 valueIdx = 0; - for (auto i = start; i < start + length; ++i, ++valueIdx) { + const qsizetype end = start + length; + for (qsizetype i = start; i < end; ++i, ++valueIdx) { const auto byteIdx = i / 8; const auto bitIdx = i % 8; if (data[byteIdx] & (0x01 << bitIdx)) @@ -852,7 +854,8 @@ char *valueData = value.data(); quint16 valueIdx = 0; - for (quint16 i = start; i < start + length; ++i, ++valueIdx) { + const qsizetype end = start + length; + for (qsizetype i = start; i < end; ++i, ++valueIdx) { const auto byteIdx = i / 8; const auto bitIdx = i % 8; if (data[byteIdx] & (0x01 << bitIdx)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanmessagedescription.cpp new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanmessagedescription.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcanmessagedescription.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcanmessagedescription.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -33,7 +33,7 @@ The QCanMessageDescription class provides methods to control all those parameters. - \section2 Message ID + \section1 Message ID The message ID is a unique identifier, which is used to select the proper message description when decoding the incoming \l QCanBusFrame or encoding a \l QCanBusFrame based on the provided data. @@ -41,7 +41,7 @@ See \l QCanUniqueIdDescription documentation for more details on the unique identifier description. - \section2 Signal Description + \section1 Signal Description The signal description is represented by the \l QCanSignalDescription class. The QCanMessageDescription class only provides a list of signals that belong to the message. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcansignaldescription.cpp new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcansignaldescription.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qcansignaldescription.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qcansignaldescription.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -21,7 +21,7 @@ and later use it to decode a received \l QCanBusFrame or encode the input data into a \l QCanBusFrame that can be sent to the receiver. - \section2 General Description + \section1 General Description Each CAN frame can contain multiple values. The rules to extract the values from a CAN frame include the following: @@ -50,7 +50,7 @@ The QCanSignalDescription class provides methods to control all those parameters. - \section2 Data Endianness Processing + \section1 Data Endianness Processing Little endian and big endian data is encoded differently. For big endian values, start bit positions are given for the most @@ -60,7 +60,7 @@ Let's consider two examples. In both examples we will encode two 12-bit values in the 3-byte payload. - \section3 Little Endian + \section2 Little Endian For the little endian case the data layout can be represented by the following image: @@ -91,7 +91,7 @@ // other parameters for signal2 \endcode - \section3 Big Endian + \section2 Big Endian The following image represents the value layout for the big endian case: @@ -119,7 +119,7 @@ Note how the start bits are different from the little endian case. Also the values are aligned differently. - \section2 Multiplexed Signals Explained + \section1 Multiplexed Signals Explained There are two common ways to encode the data in the CAN payload: \list @@ -144,7 +144,7 @@ In such cases the signal can be extracted from the payload only when all multiplexors contain the expected values. - \section2 Value Conversions + \section1 Value Conversions In many cases the signals transferred over CAN bus cannot hold the full range of the physical values that they represent. To overcome these diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbus_symbols_p.h new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbus_symbols_p.h --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbus_symbols_p.h 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbus_symbols_p.h 2026-11-16 17:43:49.000000000 +0100 @@ -16,6 +16,27 @@ // We mean it. // +#include <QtCore/qtypes.h> + +// MBAP header: transaction id (2), protocol id (2), length (2), unit id (1) +constexpr int mbapHeaderSize = 7; +// The 253 byte maximum PDU plus the MBAP header +constexpr int maxBytesModbusADU = 260; + +// The length field counts the Unit Identifier, which mbapHeaderSize already +// includes, so the frame is one byte shorter than the two added together. +constexpr int mbapAduSize(quint16 mbapLength) +{ + return mbapHeaderSize + mbapLength - 1; +} + +// The smallest frame carries a one byte PDU, the function code alone. The +// largest is a maxBytesModbusADU sized frame. +constexpr bool isValidAduSize(int aduSize) +{ + return aduSize >= mbapHeaderSize + 1 && aduSize <= maxBytesModbusADU; +} + enum Coil { On = 0xff00, Off = 0x0000 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbustcpclient_p.h new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbustcpclient_p.h --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbustcpclient_p.h 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbustcpclient_p.h 2026-11-16 17:43:49.000000000 +0100 @@ -10,6 +10,7 @@ #include <QtNetwork/qtcpsocket.h> #include "QtSerialBus/qmodbustcpclient.h" +#include "private/qmodbus_symbols_p.h" #include "private/qmodbusclient_p.h" // @@ -73,7 +74,7 @@ while (!responseBuffer.isEmpty()) { // can we read enough for Modbus ADU header? - if (responseBuffer.size() < mbpaHeaderSize) { + if (responseBuffer.size() < mbapHeaderSize) { qCDebug(QT_MODBUS_LOW) << "(TCP client) MBPA header too short. Waiting for more data."; return; } @@ -91,18 +92,29 @@ qCDebug(QT_MODBUS) << "(TCP client) tid:" << Qt::hex << transactionId << "size:" << bytesPdu << "server address:" << serverAddress; - // The length field is the byte count of the following fields, including the Unit - // Identifier and the PDU, so we remove on byte. - bytesPdu--; + const int tcpAduSize = mbapAduSize(bytesPdu); + if (!isValidAduSize(tcpAduSize)) { + // Resynchronizing would be guesswork, the next frame could start anywhere. + qCWarning(QT_MODBUS) << "(TCP client) Invalid MBAP length field:" << bytesPdu + << "closing connection."; + Q_Q(QModbusTcpClient); + m_socket->disconnectFromHost(); + q->setError(QModbusTcpClient::tr("Received invalid MBAP length field."), + QModbusDevice::ProtocolError); + return; + } - int tcpAduSize = mbpaHeaderSize + bytesPdu; if (responseBuffer.size() < tcpAduSize) { qCDebug(QT_MODBUS) << "(TCP client) PDU too short. Waiting for more data"; return; } + // Parse the PDU out of the declared frame only. QModbusPdu sizes its data + // from the function code and reads to the end of the device, so an + // unbounded stream lets it consume bytes belonging to the next frame. QModbusResponse responsePdu; - input >> responsePdu; + QDataStream pdu(responseBuffer.sliced(mbapHeaderSize, tcpAduSize - mbapHeaderSize)); + pdu >> responsePdu; qCDebug(QT_MODBUS) << "(TCP client) Received PDU:" << responsePdu.functionCode() << responsePdu.data().toHex(); @@ -226,7 +238,6 @@ QTcpSocket *m_socket = nullptr; QByteArray responseBuffer; QHash<quint16, QueueElement> m_transactionStore; - int mbpaHeaderSize = 7; private: // Private to avoid using the wrong id inside the timer lambda, quint16 m_transactionId = 0; // capturing 'this' will not copy the id. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbustcpserver_p.h new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbustcpserver_p.h --- old/qtserialbus-everywhere-src-6.12.0/src/serialbus/qmodbustcpserver_p.h 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/serialbus/qmodbustcpserver_p.h 2026-11-16 17:43:49.000000000 +0100 @@ -14,6 +14,7 @@ #include <QtNetwork/qtcpsocket.h> #include <QtSerialBus/qmodbustcpserver.h> +#include <private/qmodbus_symbols_p.h> #include <private/qmodbusserver_p.h> #include <memory> @@ -120,7 +121,7 @@ qCDebug(QT_MODBUS_LOW).noquote() << "(TCP server) Read buffer: 0x" + buffer->toHex(); - if (buffer->size() < mbpaHeaderSize) { + if (buffer->size() < mbapHeaderSize) { qCDebug(QT_MODBUS) << "(TCP server) MBPA header too short. Waiting for more data."; return; } @@ -134,18 +135,29 @@ << Qt::hex << transactionId << "Protocol Id:" << protocolId << "PDU bytes:" << bytesPdu << "Unit Id:" << unitId; - // The length field is the byte count of the following fields, including the Unit - // Identifier and the PDU, so we remove on byte. - bytesPdu--; + const int current = mbapAduSize(bytesPdu); + if (!isValidAduSize(current)) { + // Resynchronizing would be guesswork, the next frame could start + // anywhere. Disconnect before reporting, the slot may delete socket. + qCWarning(QT_MODBUS) << "(TCP server) Invalid MBAP length field:" + << bytesPdu << "closing connection."; + socket->disconnectFromHost(); + forwardError(QModbusTcpServer::tr("Received invalid MBAP length field."), + QModbusDevice::ProtocolError); + return; + } - const quint16 current = mbpaHeaderSize + bytesPdu; if (buffer->size() < current) { qCDebug(QT_MODBUS) << "(TCP server) PDU too short. Waiting for more data"; return; } + // Parse the PDU out of the declared frame only. QModbusPdu sizes its + // data from the function code and reads to the end of the device, so an + // unbounded stream lets it consume bytes belonging to the next frame. QModbusRequest request; - input >> request; + QDataStream pdu(buffer->sliced(mbapHeaderSize, current - mbapHeaderSize)); + pdu >> request; buffer->remove(0, current); @@ -192,9 +204,6 @@ QTcpServer *m_tcpServer { nullptr }; std::unique_ptr<QModbusTcpConnectionObserver> m_observer; - - static const qint8 mbpaHeaderSize = 7; - static const qint16 maxBytesModbusADU = 260; }; QT_END_NAMESPACE diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/src/tools/canbusutil/readtask.cpp new/qtserialbus-everywhere-src-6.12.1/src/tools/canbusutil/readtask.cpp --- old/qtserialbus-everywhere-src-6.12.0/src/tools/canbusutil/readtask.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/src/tools/canbusutil/readtask.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -42,7 +42,7 @@ } if (m_showFlags) { - QLatin1String flags("- - - "); + QString flags = QStringLiteral("- - - "); if (frame.hasBitrateSwitch()) flags[0] = QLatin1Char('B'); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcandbcfileparser/data/oversized_signal.dbc new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcandbcfileparser/data/oversized_signal.dbc --- old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcandbcfileparser/data/oversized_signal.dbc 1970-01-01 01:00:00.000000000 +0100 +++ new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcandbcfileparser/data/oversized_signal.dbc 2026-11-16 17:43:49.000000000 +0100 @@ -0,0 +1,4 @@ +BO_ 1234 Test : 8 Vector__XXX + SG_ goodSignal : 0|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ badStart : 70000|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ badLength : 0|70000@1+ (1,0) [0|0] "" Vector__XXX diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcandbcfileparser/tst_qcandbcfileparser.cpp new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcandbcfileparser/tst_qcandbcfileparser.cpp --- old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcandbcfileparser/tst_qcandbcfileparser.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcandbcfileparser/tst_qcandbcfileparser.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -807,6 +807,46 @@ } { + // startBit and bitLength narrow to quint16, size narrows to quint8, so a + // value above the field width must be rejected at ingestion rather than + // silently wrapped into a small, seemingly valid offset. + QCanMessageDescription oversizedMsg; + oversizedMsg.setName("Test"); + oversizedMsg.setSize(8); + oversizedMsg.setUniqueId(QtCanBus::UniqueId{1234}); + oversizedMsg.setTransmitter("Vector__XXX"); + + QCanSignalDescription goodSignal; + goodSignal.setName("goodSignal"); + goodSignal.setDataEndian(QSysInfo::Endian::LittleEndian); + goodSignal.setDataFormat(QtCanBus::DataFormat::UnsignedInteger); + goodSignal.setDataSource(QtCanBus::DataSource::Payload); + goodSignal.setStartBit(0); + goodSignal.setBitLength(8); + goodSignal.setFactor(1.0); + goodSignal.setOffset(0.0); + goodSignal.setRange(0.0, 0.0); + goodSignal.setPhysicalUnit(""); + goodSignal.setReceiver("Vector__XXX"); + oversizedMsg.addSignalDescription(goodSignal); + + const QStringList expectedWarnings = { + u"Failed to parse start bit for signal badStart"_s, + u"Failed to parse signal description from string " + "SG_ badStart : 70000|8@1+ (1,0) [0|0] \"\" Vector__XXX"_s, + u"Failed to parse bit length for signal badLength"_s, + u"Failed to parse signal description from string " + "SG_ badLength : 0|70000@1+ (1,0) [0|0] \"\" Vector__XXX"_s, + }; + + QTest::addRow("out-of-range signal fields") + << QStringList{ u"oversized_signal.dbc"_s } + << QCanDbcFileParser::Error::None << QString() + << expectedWarnings + << QList<QCanMessageDescription>{ oversizedMsg }; + } + + { // Check that we get message descriptions and warnings from all files messageDesc.clearSignalDescriptions(); messageDesc.setSize(4); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcanframeprocessor/tst_qcanframeprocessor.cpp new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcanframeprocessor/tst_qcanframeprocessor.cpp --- old/qtserialbus-everywhere-src-6.12.0/tests/auto/qcanframeprocessor/tst_qcanframeprocessor.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/tests/auto/qcanframeprocessor/tst_qcanframeprocessor.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -851,6 +851,45 @@ << QCanFrameProcessor::Error::None << QString() << expectedWarnings << QtCanBus::UniqueId(123) << QVariantMap({ qMakePair("s0", 0x0101), qMakePair("s1", 0x01) }); + + // Signals whose end-of-signal bit position exceeds 65535 must be skipped: + // that position must not truncate to a small value that passes the bounds + // check while the untruncated start bit drives the memory access. + // The end bit position calculation depends on endianness, so + // both endians are covered. + QCanMessageDescription truncationMsg; + truncationMsg.setName("truncationMessage"); + truncationMsg.setUniqueId(QtCanBus::UniqueId{123}); + truncationMsg.setSize(8); + + QCanSignalDescription oobLittleEndian; + oobLittleEndian.setName("oobLittleEndian"); + oobLittleEndian.setDataEndian(QSysInfo::Endian::LittleEndian); + oobLittleEndian.setDataFormat(QtCanBus::DataFormat::UnsignedInteger); + oobLittleEndian.setStartBit(65480); // 65480 + 64 - 1 = 65543, truncates to 7 + oobLittleEndian.setBitLength(64); + truncationMsg.addSignalDescription(oobLittleEndian); + + QCanSignalDescription oobBigEndian; + oobBigEndian.setName("oobBigEndian"); + oobBigEndian.setDataEndian(QSysInfo::Endian::BigEndian); + oobBigEndian.setDataFormat(QtCanBus::DataFormat::UnsignedInteger); + oobBigEndian.setStartBit(65535); // last byte 8199 -> bit 65591, truncates to 55 + oobBigEndian.setBitLength(64); + truncationMsg.addSignalDescription(oobBigEndian); + + const QStringList truncationWarnings = { + tr("Skipping signal oobLittleEndian in message with unique id 123. " + "Its expected length exceeds the data length."), + tr("Skipping signal oobBigEndian in message with unique id 123. " + "Its expected length exceeds the data length.") + }; + + QTest::addRow("signal offset exceeds quint16") + << truncationMsg << uidDesc << QCanBusFrame(123, QByteArray(8, 0x41)) + << QCanFrameProcessor::Error::None << QString() + << truncationWarnings << QtCanBus::UniqueId(123) + << QVariantMap(); } void tst_QCanFrameProcessor::parseWithErrorsAndWarnings() @@ -1726,6 +1765,31 @@ << QCanFrameProcessor::Error::None << QString() << warnings << QCanBusFrame::FrameId(messageDesc.uniqueId()) << QByteArray::fromHex("1205"); + + // A signal whose (startBit + bitLength) exceeds 65535 must be skipped, not + // encoded: otherwise the truncated end-of-signal position passes the bounds + // check while the untruncated start offset drives an out-of-bounds write. + QCanMessageDescription truncationMsg; + truncationMsg.setUniqueId(QtCanBus::UniqueId{123}); + truncationMsg.setSize(8); + + QCanSignalDescription oobWrite; + oobWrite.setName("oobWrite"); + oobWrite.setDataEndian(QSysInfo::Endian::LittleEndian); + oobWrite.setDataFormat(QtCanBus::DataFormat::UnsignedInteger); + oobWrite.setStartBit(65480); // 65480 + 64 - 1 = 65543, truncates to 7 + oobWrite.setBitLength(64); + truncationMsg.addSignalDescription(oobWrite); + + QTest::addRow("signal offset exceeds quint16") + << truncationMsg << uidDesc << truncationMsg.uniqueId() + << QVariantMap({ qMakePair("oobWrite", + QVariant::fromValue<quint64>(0xdeadbeefcafebabeULL)) }) + << QCanFrameProcessor::Error::None << QString() + << QStringList{ tr("Skipping signal oobWrite. Its length exceeds the " + "expected message length.") } + << QCanBusFrame::FrameId(truncationMsg.uniqueId()) + << QByteArray(8, 0x00); } void tst_QCanFrameProcessor::prepareWithErrorsAndWarnings() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/tests/auto/qmodbusclient/tst_qmodbusclient.cpp new/qtserialbus-everywhere-src-6.12.1/tests/auto/qmodbusclient/tst_qmodbusclient.cpp --- old/qtserialbus-everywhere-src-6.12.0/tests/auto/qmodbusclient/tst_qmodbusclient.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/tests/auto/qmodbusclient/tst_qmodbusclient.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -2,9 +2,13 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtSerialBus/qmodbusclient.h> +#include <QtSerialBus/qmodbustcpclient.h> #include <private/qmodbusclient_p.h> #include <private/qmodbus_symbols_p.h> +#include <QtCore/qendian.h> +#include <QtNetwork/qtcpserver.h> +#include <QtNetwork/qtcpsocket.h> #include <QtTest/QtTest> class TestClient : public QModbusClient @@ -571,6 +575,74 @@ QCOMPARE(client.d_func()->sendRequest(request, 1, &unit), reply); QCOMPARE(client.d_func()->sendRequest(request, 1, nullptr), reply); } + + void testTcpMbapLengthField_data() + { + QTest::addColumn<QByteArray>("frame"); + QTest::addColumn<bool>("accepted"); + + // MBAP header: transaction id (2), protocol id (2), length (2), unit id (1). + // The length field counts the unit id, so 2 is its smallest legal value. + QTest::newRow("length zero") << QByteArray::fromHex("00000000000001") << false; + QTest::newRow("length one") << QByteArray::fromHex("00000000000101") << false; + QTest::newRow("one above the maximum") << QByteArray::fromHex("0000000000ff01") << false; + QTest::newRow("length huge") << QByteArray::fromHex("00000000ffff01") << false; + // 254 describes the largest legal frame, a 260 byte ADU. It is accepted by + // the framing, here rejected later because the padding is not a valid PDU. + QTest::newRow("maximum length") + << (QByteArray::fromHex("0000000000fe01") + QByteArray(253, 0x03)) << true; + + // A legal length of 2 declares a one byte PDU, too short for the read + // response it claims to be. The missing bytes must not be taken from what + // follows the frame, or the application is handed a fabricated register. + QTest::newRow("declared length bounds the PDU") + << (QByteArray::fromHex("0000000000020103") + QByteArray::fromHex("02beef")) << true; + } + + void testTcpMbapLengthField() + { + QFETCH(QByteArray, frame); + QFETCH(bool, accepted); + + QTcpServer server; + QVERIFY(server.listen(QHostAddress::LocalHost, 0)); + + QModbusTcpClient client; + client.setConnectionParameter(QModbusDevice::NetworkAddressParameter, + QStringLiteral("127.0.0.1")); + client.setConnectionParameter(QModbusDevice::NetworkPortParameter, server.serverPort()); + QVERIFY(client.connectDevice()); + QTRY_COMPARE(client.state(), QModbusDevice::ConnectedState); + QTRY_VERIFY(server.hasPendingConnections()); + QTcpSocket *remote = server.nextPendingConnection(); + + QModbusReply *reply = client.sendReadRequest( + QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 0, 1), 1); + QVERIFY(reply); + + if (!accepted) { + const QByteArray warning = "(TCP client) Invalid MBAP length field: " + + QByteArray::number(qFromBigEndian<quint16>(frame.constData() + 4)) + + " closing connection."; + QTest::ignoreMessage(QtWarningMsg, warning.constData()); + } + + remote->write(frame); + QTRY_VERIFY(reply->isFinished()); + + if (!accepted) { + QCOMPARE(reply->error(), QModbusDevice::ReplyAbortedError); + QTRY_COMPARE(client.state(), QModbusDevice::UnconnectedState); + QCOMPARE(client.error(), QModbusDevice::ProtocolError); + return; + } + + // Accepted by the framing, so the connection survives and only the + // bogus PDU is rejected. No value reaches the application. + QCOMPARE(reply->error(), QModbusDevice::InvalidResponseError); + QCOMPARE(reply->result().valueCount(), 0); + QCOMPARE(client.state(), QModbusDevice::ConnectedState); + } }; QTEST_MAIN(tst_QModbusClient) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/qtserialbus-everywhere-src-6.12.0/tests/auto/qmodbusserver/tst_qmodbusserver.cpp new/qtserialbus-everywhere-src-6.12.1/tests/auto/qmodbusserver/tst_qmodbusserver.cpp --- old/qtserialbus-everywhere-src-6.12.0/tests/auto/qmodbusserver/tst_qmodbusserver.cpp 2026-09-26 12:43:40.000000000 +0200 +++ new/qtserialbus-everywhere-src-6.12.1/tests/auto/qmodbusserver/tst_qmodbusserver.cpp 2026-11-16 17:43:49.000000000 +0100 @@ -9,6 +9,9 @@ #include <QtSerialBus/qmodbusdeviceidentification.h> #include <QtCore/qdebug.h> +#include <QtCore/qendian.h> +#include <QtNetwork/qtcpserver.h> +#include <QtNetwork/qtcpsocket.h> #include <QtTest/QtTest> class TestServer : public QModbusServer @@ -1200,6 +1203,84 @@ QCOMPARE(local.processRequest(request).exceptionCode(), QModbusPdu::IllegalFunction); } + void testTcpMbapLengthField_data() + { + QTest::addColumn<QByteArray>("wire"); + QTest::addColumn<QByteArray>("expected"); + + // A valid request, appended to every rejected frame: it must not be + // answered out of a desynchronized buffer. + const QByteArray request = QByteArray::fromHex("000100000006ff0300000001"); + + // MBAP header: transaction id (2), protocol id (2), length (2), unit id (1). + // The length field counts the unit id, so 2 is its smallest legal value. + QTest::newRow("length zero") + << QByteArray::fromHex("000200000000ff") + request << QByteArray(); + QTest::newRow("length one") + << QByteArray::fromHex("000200000001ff") + request << QByteArray(); + QTest::newRow("one above the maximum") + << QByteArray::fromHex("0002000000ffff") + request << QByteArray(); + QTest::newRow("length huge") + << QByteArray::fromHex("00020000ffffff") + request << QByteArray(); + + // 254 describes the largest legal frame, a 260 byte ADU. It is answered, + // here with an exception because the padding is not a valid PDU. + QTest::newRow("maximum length") + << QByteArray::fromHex("0002000000feff") + QByteArray(253, 0x03) + << QByteArray::fromHex("000200000003ff8303"); + + // A legal length of 2 declares a one byte PDU, too short for the function + // code it carries. The missing bytes must not be taken from the request + // that follows: the short frame is answered with an exception and the + // following request with its own correct response. + QTest::newRow("declared length bounds the PDU") + << QByteArray::fromHex("00bb00000002ff03") + request + << QByteArray::fromHex("00bb00000003ff8001") + + QByteArray::fromHex("000100000005ff03020000"); + } + + void testTcpMbapLengthField() + { + QFETCH(QByteArray, wire); + QFETCH(QByteArray, expected); + + QModbusTcpServer modbusServer; + modbusServer.setMap({ { QModbusDataUnit::HoldingRegisters, + { QModbusDataUnit::HoldingRegisters, 0, MAP_RANGE } } }); + modbusServer.setConnectionParameter(QModbusDevice::NetworkAddressParameter, + QStringLiteral("127.0.0.1")); + modbusServer.setConnectionParameter(QModbusDevice::NetworkPortParameter, 0); + QVERIFY(modbusServer.connectDevice()); + + // The listening socket is a child, so the port the OS picked is reachable + // without binding a second time and racing for the same port. + auto *listener = modbusServer.findChild<QTcpServer *>(); + QVERIFY(listener); + + QTcpSocket socket; + socket.connectToHost(QHostAddress::LocalHost, listener->serverPort()); + QTRY_COMPARE(socket.state(), QAbstractSocket::ConnectedState); + + if (expected.isEmpty()) { + const QByteArray warning = "(TCP server) Invalid MBAP length field: " + + QByteArray::number(qFromBigEndian<quint16>(wire.constData() + 4)) + + " closing connection."; + QTest::ignoreMessage(QtWarningMsg, warning.constData()); + } + + socket.write(wire); + if (expected.isEmpty()) { + QTRY_COMPARE(socket.state(), QAbstractSocket::UnconnectedState); + QCOMPARE(socket.readAll(), QByteArray()); + QCOMPARE(modbusServer.error(), QModbusDevice::ProtocolError); + return; + } + + QTRY_COMPARE(socket.bytesAvailable(), qint64(expected.size())); + QCOMPARE(socket.readAll(), expected); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + } + void testQModbusServerOptions() { // TODO: Add a local class implementation to test value()/setValue with a different backing
