linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #06745
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3253: Validate input before trying a TTH search
------------------------------------------------------------
revno: 3253
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2013-04-09 19:20:25 +0200
message:
Validate input before trying a TTH search
modified:
changelog.txt
dcpp/Encoder.cpp
dcpp/Encoder.h
win32/SearchFrame.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2013-03-31 17:09:29 +0000
+++ changelog.txt 2013-04-09 17:20:25 +0000
@@ -3,6 +3,7 @@
* Merge connections, downloads and uploads in the same list (poy)
* [L#249622] Add user commands to transfer menus
* Add a tab menu command to disconnect a hub (poy)
+* Validate input before trying a TTH search (emtee)
-- 0.811 2013-03-04 --
* Fix status bar parts when the window is too small (poy)
=== modified file 'dcpp/Encoder.cpp'
--- dcpp/Encoder.cpp 2013-01-18 21:28:38 +0000
+++ dcpp/Encoder.cpp 2013-04-09 17:20:25 +0000
@@ -109,6 +109,10 @@
}
}
+bool Encoder::isBase32(const string& str) {
+ return str.find_first_not_of(base32Alphabet) == string::npos;
+}
+
uint8_t decode16(char c) {
if (c >= '0' && c <= '9')
return c - '0';
=== modified file 'dcpp/Encoder.h'
--- dcpp/Encoder.h 2013-01-18 21:28:38 +0000
+++ dcpp/Encoder.h 2013-04-09 17:20:25 +0000
@@ -34,6 +34,7 @@
return toBase32(src, len, tmp);
}
static void fromBase32(const char* src, uint8_t* dst, size_t len);
+ static bool isBase32(const string& str);
static void fromBase16(const char* src, uint8_t *dst, size_t len);
private:
=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp 2013-03-22 14:59:39 +0000
+++ win32/SearchFrame.cpp 2013-04-09 17:20:25 +0000
@@ -22,6 +22,7 @@
#include <boost/range/adaptor/reversed.hpp>
#include <dcpp/ClientManager.h>
+#include <dcpp/Encoder.h>
#include <dcpp/FavoriteManager.h>
#include <dcpp/GeoManager.h>
#include <dcpp/QueueManager.h>
@@ -948,6 +949,19 @@
if(s.empty())
return;
+ int ftype = fileType->getData(fileType->getSelected());
+ if(ftype == SearchManager::TYPE_TTH) {
+ auto s8 = Text::fromT(s);
+ s8.erase(std::remove_if(s8.begin(), s8.end(), [](char c) { return c == ' ' || c == '\t' || c == '\r' || c == '\n'; }), s8.end());
+ if(s8.size() != 39 || !Encoder::isBase32(s8)) {
+ auto text = T_("Invalid input value for TTH search");
+ status->setText(STATUS_STATUS, text);
+ setText(str(TF_("Search - %1%") % text));
+ return;
+ }
+ s = Text::toT(s8);
+ }
+
StringList clients;
for(size_t i = 0, n = hubs->size(); i < n; ++i) {
if(hubs->isChecked(i)) {
@@ -1003,8 +1017,6 @@
if(llsize == 0)
searchMode = SearchManager::SIZE_DONTCARE;
- int ftype = fileType->getData(fileType->getSelected());
-
// Get ADC searchtype extensions if any is selected
StringList extList;
try {