From 58f30fd0e577f534ac738d4f4ac1a935ed12aa3a Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 5 Aug 2013 16:40:40 +0800 Subject: [PATCH] + fix escaping character (%) parser in url parsing --- src/common/kiwix/reader.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 4f7e2d071..2a928c080 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -27,11 +27,10 @@ static char charFromHex(std::string a) { } void unescapeUrl(string &url) { - std::string::size_type pos; - std::string hex; - while (std::string::npos != (pos = url.find('%'))) { - hex = url.substr(pos + 1, 2); - url.replace(pos, 3, 1, charFromHex(hex)); + std::string::size_type pos = 0; + while ((pos = url.find('%', pos + 1)) != std::string::npos && + pos + 3 <= url.length()) { + url.replace(pos, 3, 1, charFromHex(url.substr(pos + 1, 2))); } return; }