From 357cf76409d30341a2c4eedcf2568f0abd56e88d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 6 Jun 2020 15:13:39 +0200 Subject: More runtime error checking --- plugins/weblog/weblog.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugins/weblog') diff --git a/plugins/weblog/weblog.cpp b/plugins/weblog/weblog.cpp index 1e1b6b2..a64ee1b 100644 --- a/plugins/weblog/weblog.cpp +++ b/plugins/weblog/weblog.cpp @@ -244,6 +244,9 @@ namespace { size_t page) { try { + if (page > std::numeric_limits::max()) + throw std::runtime_error("Bad page index: "s + std::to_string(page)); + HtmlPage htmlPage{GetRequestParam, "

"s + GetRequestParam("WEBLOG_NAME") + "

"s}; fs::path link{ GetRequestParam("plugin_path")}; @@ -422,7 +425,11 @@ std::string weblog_plugin::generate_page( size_t page {0}; auto it {query.find("page")}; if (it != query.end()) { - page = stoul(it->second); + try { + page = stoul(it->second); + } catch(...) { + // ignore: keep default 0 + } } if (is_index_page(rel_target)) -- cgit v1.2.3