FIXED: kiwix-serve crash if unattended search "start" & "end" values

This commit is contained in:
kelson42 2014-08-28 13:36:58 -06:00
parent 518ce6635d
commit f585bed1cb
4 changed files with 45 additions and 25 deletions

View File

@ -39,21 +39,39 @@ namespace kiwix {
} }
/* Search strings in the database */ /* Search strings in the database */
void Searcher::search(std::string &search, const unsigned int resultStart, void Searcher::search(std::string &search, unsigned int resultStart,
const unsigned int resultEnd, const bool verbose) { unsigned int resultEnd, const bool verbose) {
this->reset(); this->reset();
if (verbose == true) { if (verbose == true) {
cout << "Performing query `" << search << "'" << endl; cout << "Performing query `" << search << "'" << endl;
} }
this->searchPattern = search; /* If resultEnd & resultStart inverted */
this->resultCountPerPage = resultEnd - resultStart; if (resultStart > resultEnd) {
this->resultStart = resultStart; resultEnd += resultStart;
this->resultEnd = resultEnd; resultStart = resultEnd - resultStart;
string unaccentedSearch = removeAccents(search); resultEnd -= resultStart;
searchInIndex(unaccentedSearch, resultStart, resultEnd, verbose); }
this->resultOffset = this->results.begin();
/* Try to find results */
if (resultStart != resultEnd) {
/* Avoid big researches */
this->resultCountPerPage = resultEnd - resultStart;
if (this->resultCountPerPage > 70) {
resultEnd = resultStart + 70;
this->resultCountPerPage = 70;
}
/* Perform the search */
this->searchPattern = search;
this->resultStart = resultStart;
this->resultEnd = resultEnd;
string unaccentedSearch = removeAccents(search);
searchInIndex(unaccentedSearch, resultStart, resultEnd, verbose);
this->resultOffset = this->results.begin();
}
return; return;
} }

View File

@ -59,8 +59,8 @@ namespace kiwix {
public: public:
Searcher(); Searcher();
void search(std::string &search, const unsigned int resultStart, void search(std::string &search, unsigned int resultStart,
const unsigned int resultEnd, const bool verbose=false); unsigned int resultEnd, const bool verbose=false);
bool getNextResult(string &url, string &title, unsigned int &score); bool getNextResult(string &url, string &title, unsigned int &score);
unsigned int getEstimatedResultCount(); unsigned int getEstimatedResultCount();
bool setProtocolPrefix(const std::string prefix); bool setProtocolPrefix(const std::string prefix);

View File

@ -38703,20 +38703,21 @@ const unsigned char server_taskbar_css[]={
0x69,0x78,0x73,0x65,0x61,0x72,0x63,0x68,0x62,0x6f,0x78,0x20,0x7b,0x0a,0x20,0x20, 0x69,0x78,0x73,0x65,0x61,0x72,0x63,0x68,0x62,0x6f,0x78,0x20,0x7b,0x0a,0x20,0x20,
0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,0x20,0x30,0x70,0x78,0x3b,0x0a,0x20, 0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,0x20,0x30,0x70,0x78,0x3b,0x0a,0x20,
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3a,0x20,0x72,0x69,0x67,0x68,0x74,0x3b, 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3a,0x20,0x72,0x69,0x67,0x68,0x74,0x3b,
0x0a,0x7d,0x0a,0x0a,0x23,0x6b,0x69,0x77,0x69,0x78,0x73,0x65,0x61,0x72,0x63,0x68, 0x0a,0x20,0x20,0x20,0x20,0x77,0x69,0x64,0x74,0x68,0x3a,0x20,0x33,0x30,0x30,0x70,
0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,0x20,0x30, 0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x23,0x6b,0x69,0x77,0x69,0x78,0x73,0x65,0x61,0x72,
0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3a,0x20,0x72, 0x63,0x68,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,
0x69,0x67,0x68,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x2f,0x2a,0x20,0x54,0x72,0x79,0x20, 0x20,0x30,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3a,
0x74,0x6f,0x20,0x66,0x69,0x78,0x20,0x62,0x75,0x67,0x67,0x79,0x20,0x73,0x74,0x75, 0x20,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x2f,0x2a,0x20,0x54,0x72,
0x66,0x66,0x20,0x69,0x6e,0x20,0x6a,0x71,0x75,0x65,0x72,0x79,0x2d,0x75,0x69,0x20, 0x79,0x20,0x74,0x6f,0x20,0x66,0x69,0x78,0x20,0x62,0x75,0x67,0x67,0x79,0x20,0x73,
0x61,0x75,0x74,0x6f,0x63,0x6f,0x6d,0x70,0x6c,0x65,0x74,0x65,0x20,0x2a,0x2f,0x0a, 0x74,0x75,0x66,0x66,0x20,0x69,0x6e,0x20,0x6a,0x71,0x75,0x65,0x72,0x79,0x2d,0x75,
0x23,0x75,0x69,0x2d,0x69,0x64,0x2d,0x31,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62, 0x69,0x20,0x61,0x75,0x74,0x6f,0x63,0x6f,0x6d,0x70,0x6c,0x65,0x74,0x65,0x20,0x2a,
0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x3a,0x20,0x77,0x68,0x69,0x74,0x65, 0x2f,0x0a,0x23,0x75,0x69,0x2d,0x69,0x64,0x2d,0x31,0x20,0x7b,0x0a,0x20,0x20,0x20,
0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x72,0x64,0x65,0x72,0x3a,0x20,0x73,0x6f, 0x20,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x3a,0x20,0x77,0x68,0x69,
0x6c,0x69,0x64,0x20,0x31,0x70,0x78,0x20,0x67,0x72,0x65,0x79,0x3b,0x0a,0x7d,0x0a, 0x74,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x72,0x64,0x65,0x72,0x3a,0x20,
0x0a,0x6c,0x69,0x2e,0x75,0x69,0x2d,0x73,0x74,0x61,0x74,0x65,0x2d,0x66,0x6f,0x63, 0x73,0x6f,0x6c,0x69,0x64,0x20,0x31,0x70,0x78,0x20,0x67,0x72,0x65,0x79,0x3b,0x0a,
0x75,0x73,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x77,0x65, 0x7d,0x0a,0x0a,0x6c,0x69,0x2e,0x75,0x69,0x2d,0x73,0x74,0x61,0x74,0x65,0x2d,0x66,
0x69,0x67,0x68,0x74,0x3a,0x20,0x62,0x6f,0x6c,0x64,0x3b,0x0a,0x7d 0x6f,0x63,0x75,0x73,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,
0x77,0x65,0x69,0x67,0x68,0x74,0x3a,0x20,0x62,0x6f,0x6c,0x64,0x3b,0x0a,0x7d
}; };
const unsigned char server_include_html_part[]={ const unsigned char server_include_html_part[]={

View File

@ -27,6 +27,7 @@
#kiwixsearchbox { #kiwixsearchbox {
margin: 0px; margin: 0px;
float: right; float: right;
width: 300px;
} }
#kiwixsearch { #kiwixsearch {