From 3784118bb291113e18457d00e4b52747987c7923 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 12 Feb 2013 18:55:09 +0000 Subject: [PATCH] * FIXED: kiwix-serve crahs if really long URL (#400) --- src/common/kiwix/reader.cpp | 20 +++++++------------- src/common/kiwix/reader.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index c2fa9810a..94370dc19 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -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; } diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index 0f51f3b3a..dec5c8be7 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -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();