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

View File

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