mirror of
git://git.openembedded.org/meta-openembedded
synced 2026-10-02 17:12:39 +00:00
59 lines
1.6 KiB
Diff
59 lines
1.6 KiB
Diff
From 4ff83fc53b2c7462b02f804ee20414d85944e3c9 Mon Sep 17 00:00:00 2001
|
|
From: chros <chros@chrosGX620>
|
|
Date: Sun, 14 May 2017 19:36:09 +0100
|
|
Subject: [PATCH] Display info on failed tracker bencode parsing (See #9)
|
|
|
|
---
|
|
rak/string_manip.h | 20 ++++++++++++++++++++
|
|
src/tracker/tracker_http.cc | 6 ++++--
|
|
2 files changed, 24 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/rak/string_manip.h b/rak/string_manip.h
|
|
index f8d3f590..68614d2a 100644
|
|
--- a/rak/string_manip.h
|
|
+++ b/rak/string_manip.h
|
|
@@ -371,6 +371,26 @@ is_all_name(const Sequence& src) {
|
|
return is_all_name(src.begin(), src.end());
|
|
}
|
|
|
|
+template <typename Iterator>
|
|
+std::string
|
|
+sanitize(Iterator first, Iterator last) {
|
|
+ std::string dest;
|
|
+ for (; first != last; ++first) {
|
|
+ if (std::isprint(*first) && *first != '\r' && *first != '\n' && *first != '\t')
|
|
+ dest += *first;
|
|
+ else
|
|
+ dest += " ";
|
|
+ }
|
|
+
|
|
+ return dest;
|
|
+}
|
|
+
|
|
+template <typename Sequence>
|
|
+std::string
|
|
+sanitize(const Sequence& src) {
|
|
+ return trim(sanitize(src.begin(), src.end()));
|
|
+}
|
|
+
|
|
}
|
|
|
|
#endif
|
|
diff --git a/src/tracker/tracker_http.cc b/src/tracker/tracker_http.cc
|
|
index 553f922c..b6d9e0ac 100644
|
|
--- a/src/tracker/tracker_http.cc
|
|
+++ b/src/tracker/tracker_http.cc
|
|
@@ -288,8 +288,10 @@ TrackerHttp::receive_done() {
|
|
Object b;
|
|
*m_data >> b;
|
|
|
|
- if (m_data->fail())
|
|
- return receive_failed("Could not parse bencoded data");
|
|
+ if (m_data->fail()) {
|
|
+ std::string dump = m_data->str();
|
|
+ return receive_failed("Could not parse bencoded data: " + rak::sanitize(dump).substr(0,99));
|
|
+ }
|
|
|
|
if (!b.is_map())
|
|
return receive_failed("Root not a bencoded map");
|