diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-02-17 17:58:35 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-18 20:20:03 +0000 |
commit | e3257c2a91cab4e15e95c6d1e70ab23c77be58a7 (patch) | |
tree | f0e1137eecf7f3348b498bb7aa1c19a204912a36 | |
parent | e673d5602511af1b216e9d2b010a5a5039e5a7b0 (diff) | |
download | qtconnectivity-e3257c2a91cab4e15e95c6d1e70ab23c77be58a7.tar.gz |
sdpscanner: fix potential unwanted truncation for SDP_TEXT_STR{8,16,32}
QByteArray::resize() treats all negative parameters as a request for
a zero length. So the code
text.resize(text.indexOf('\0'));
can completely erase the text if there is no '\0' in it.
Fix it by explicitly checking the return value of QByteArray::indexOf().
Change-Id: Idc42bf4b96a9be5b007916263d6cf1e831b96c07
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 58cb7eeea5c05e42efc806716eb5eb39bd25787b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/tools/sdpscanner/main.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/tools/sdpscanner/main.cpp b/src/tools/sdpscanner/main.cpp index 1f62d2a7..d0c3e2cc 100644 --- a/src/tools/sdpscanner/main.cpp +++ b/src/tools/sdpscanner/main.cpp @@ -123,7 +123,9 @@ static void parseAttributeValues(sdp_data_t *data, int indentation, QByteArray & break; } else if (!isprint(text[i])) { hasNonPrintableChar = true; - text.resize(text.indexOf('\0')); // cut trailing content + const auto firstNullIdx = text.indexOf('\0'); + if (firstNullIdx > 0) + text.resize(firstNullIdx); // cut trailing content break; } } |