summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-02-22 15:41:59 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-23 21:00:25 +0000
commitd61addabefc8afc3b6211eaecee1fa0ec828fc36 (patch)
tree0b0a04141d2d7f5575d2d076954a7235866500bc
parent760cd4371068e8f9fb0d0d2f78f9bb0c3ba85791 (diff)
SDP scanner: encode input URLs and escape XML-specific characters6.4
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 Change-Id: I6de080fef7689ef96fe5e5e26c62a3c48ebc45b7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit d195ae3a07dcd3fceeb70554ed9493f55ef50c86) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/tools/sdpscanner/main.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/tools/sdpscanner/main.cpp b/src/tools/sdpscanner/main.cpp
index d0c3e2cc..6d9965f1 100644
--- a/src/tools/sdpscanner/main.cpp
+++ b/src/tools/sdpscanner/main.cpp
@@ -3,6 +3,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
+#include <QtCore/QUrl>
#include <stdio.h>
#include <string>
#include <bluetooth/bluetooth.h>
@@ -177,10 +178,17 @@ static void parseAttributeValues(sdp_data_t *data, int indentation, QByteArray &
case SDP_URL_STR8:
case SDP_URL_STR16:
case SDP_URL_STR32:
+ {
xmlOutput.append("<url value=\"");
- xmlOutput.append(data->val.str, qstrnlen(data->val.str, data->unitSize));
+ const QByteArray urlData =
+ QByteArray::fromRawData(data->val.str, qstrnlen(data->val.str, data->unitSize));
+ const QUrl url = QUrl::fromEncoded(urlData);
+ // Encoded url %-encodes all of the XML special characters except '&',
+ // so we need to do that manually
+ xmlOutput.append(url.toEncoded().replace('&', "&amp;"));
xmlOutput.append("\"/>\n");
break;
+ }
default:
fprintf(stderr, "Unknown dtd type\n");
}