Skip to content

[3 patches] sdpscanner: various fixes

Fixes: https://bugreports.qt.io/browse/QTBUG-111242 https://bugreports.qt.io/browse/QTBUG-111369 (no access)

[PATCH 1/3] 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().

Pick-to: 6.5 6.4 6.2 5.15
Change-Id: Idc42bf4b96a9be5b007916263d6cf1e831b96c07
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 58cb7eeea5c05e42efc806716eb5eb39bd25787b)
---
 src/tools/sdpscanner/main.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

[PATCH 2/3] sdpscanner: fix URL processing

Do not use the fixed-size temporary buffer, instead just parse the
data as a QByteArray.

Grepping through BlueZ sources, I could find only several usages of
SDP_URL_STR{8,16,32}, and all of them suggest that the url is simply
a NULL-terminated string (see [0], [1], [2]).
However, the older BlueZ sources suggest that the url can be not
NULL-terminated as well (see [3]).

To be on a safe side, we provide an implementation that handles both
cases correctly.

[0]: https://github.com/bluez/bluez/blob/9be85f867856195e16c9b94b605f65f6389eda33/lib/sdp.c#L465
[1]: https://github.com/bluez/bluez/blob/9be85f867856195e16c9b94b605f65f6389eda33/src/sdp-xml.c#L351
[2]: https://github.com/bluez/bluez/blob/9be85f867856195e16c9b94b605f65f6389eda33/tools/sdptool.c#L517

[3]: https://android.googlesource.com/platform/external/bluetooth/bluez/+/master/src/sdp-xml.c#324

Fixes: QTBUG-111242
Pick-to: 6.5 6.4 6.2 5.15
Change-Id: I22f9521582863fb316dd0b2c49a78928b80a6078
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit a811bcb3e76e98d480581634b84daf5c8948aceb)
---
 src/tools/sdpscanner/main.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

[PATCH 3/3] SDP scanner: encode input URLs and escape XML-specific characters

The old implementation didn't take care of escaping the XML-specific
characters and didn't handle non-printable characters.

This patch makes use of QUrl class to properly %-encode the input data.
The QUrl::toEncoded() method %-encodes all XML-specific characters
except '&', so we need to manually replace it with "&amp;" before
adding the url to the generated XML.

Escaping special XML characters potentially allows Qt Bluetooth to
handle more URLs received from sdpscanner, because QXmlStreamReader
discards attributes with unescaped special characters, so previously
part of the URLs could be silently skipped.
For other potential sdpscanner users this change shouldn't make much
difference, because they should anyway parse the returned XML documents
according to XML standard.

%-encoding of URLs potentially changes the way the URL looks for the
user, but not for the software that should handle the URLs, so this
change is also safe.

[ChangeLog][Qt Bluetooth][sdpscanner] sdpscanner now %-encodes the
URLs and escapes all XML-specific characters in them before adding
the result to the generated XML output.

Fixes: QTBUG-111369
Pick-to: 6.5 6.4 6.4.3 6.2 5.15
Change-Id: I6de080fef7689ef96fe5e5e26c62a3c48ebc45b7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit d195ae3a07dcd3fceeb70554ed9493f55ef50c86)
---
 src/tools/sdpscanner/main.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Merge request reports