diff options
author | Mate Barany <mate.barany@qt.io> | 2022-08-11 16:08:28 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-22 10:51:22 +0000 |
commit | 3f8990b9047ba691d0c1f1f889bdd8e795964157 (patch) | |
tree | 70c39eb7cbe15bc456f7e9306b777f450c1510e6 | |
parent | 1660bc199a6f12daa509cdbf4425f09d22b91751 (diff) |
Add check to getSatInfoFromNmea to avoid undefined behavior
Before the iteration so far the only check is
parts.size() > 3, however in itself it is not enough
to rule out undefined behavior.
Add an explicit check to make sure that there are
enough elements to iterate over.
Change-Id: I2b528049922ec93df28f5f626b42b36c4467e141
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit d1c8c2371986eb33e0b9a718b106e50a2ed0214c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/positioning/qlocationutils.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/positioning/qlocationutils.cpp b/src/positioning/qlocationutils.cpp index 7174444a..23782baa 100644 --- a/src/positioning/qlocationutils.cpp +++ b/src/positioning/qlocationutils.cpp @@ -421,6 +421,10 @@ QLocationUtils::getSatInfoFromNmea(const char *data, int size, QList<QGeoSatelli infos.clear(); const int numSatInSentence = qMin(sentence * 4, totalSats) - (sentence - 1) * 4; + if (parts.size() < (4 + numSatInSentence * 4)) { + infos.clear(); + return QNmeaSatelliteInfoSource::FullyParsed; // Malformed sentence. + } int field = 4; for (int i = 0; i < numSatInSentence; ++i) { |