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 21:20:05 +0000 |
commit | c2fa8ee0ca5e1c8e1fe16fc735fd4614435c80a5 (patch) | |
tree | 2bf5562c2cf2b80f1b457e46564a477b6e273fc3 | |
parent | 092d5f8cbda2d62264626a9a4aab1ecc37a0facb (diff) |
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 1df84eba..690f9aaa 100644 --- a/src/tools/sdpscanner/main.cpp +++ b/src/tools/sdpscanner/main.cpp @@ -159,7 +159,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; } } |