* FIXED: kiwix-serve crahs if really long URL (#400)

This commit is contained in:
kelson42 2013-02-12 18:55:09 +00:00
parent 36f0b977f7
commit 3784118bb2
2 changed files with 8 additions and 14 deletions

View File

@ -295,11 +295,9 @@ namespace kiwix {
return url; return url;
} }
bool Reader::parseUrl(const string &urlStr, char *ns, string &titleStr) { bool Reader::parseUrl(const string &url, char *ns, string &title) {
const char *url = urlStr.c_str();
/* Offset to visit the url */ /* Offset to visit the url */
unsigned int urlLength = strlen(url); unsigned int urlLength = url.size();
unsigned int offset = 0; unsigned int offset = 0;
/* Ignore the '/' */ /* Ignore the '/' */
@ -315,18 +313,14 @@ namespace kiwix {
while ((offset < urlLength) && (url[offset] == '/')) offset++; while ((offset < urlLength) && (url[offset] == '/')) offset++;
/* Get content title */ /* Get content title */
char title[1024]; unsigned int titleOffset = offset;
unsigned int titleOffset = 0;
while (offset < urlLength) { while (offset < urlLength) {
title[titleOffset] = url[offset];
offset++; offset++;
titleOffset++;
} }
title[titleOffset] = 0;
/* unescape title */
/* unescape url */ title = url.substr(titleOffset, offset - titleOffset);
titleStr = string(title); unescapeUrl(title);
unescapeUrl(titleStr);
return true; return true;
} }

View File

@ -66,7 +66,7 @@ namespace kiwix {
bool getNextSuggestion(string &title); bool getNextSuggestion(string &title);
bool canCheckIntegrity(); bool canCheckIntegrity();
bool isCorrupted(); bool isCorrupted();
bool parseUrl(const string &urlStr, char *ns, string &titleStr); bool parseUrl(const string &url, char *ns, string &title);
unsigned int getFileSize(); unsigned int getFileSize();
zim::File* getZimFileHandler(); zim::File* getZimFileHandler();