Skip to content

Commit c19ad54

Browse files
committed
added protection against empty get_found_bp result.
1 parent 1fcba8a commit c19ad54

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

include/crow/routing.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <algorithm>
1111
#include <type_traits>
1212
#include <optional>
13+
#include <limits>
1314

1415
#include "crow/common.h"
1516
#include "crow/http_response.h"
@@ -24,7 +25,7 @@
2425
namespace crow // NOTE: Already documented in "crow/app.h"
2526
{
2627

27-
constexpr size_t INVALID_BP_ID{SIZE_T_MAX};
28+
constexpr size_t INVALID_BP_ID{SIZE_MAX};
2829

2930
namespace detail
3031
{
@@ -721,7 +722,6 @@ namespace crow // NOTE: Already documented in "crow/app.h"
721722

722723
constexpr size_t RULE_SPECIAL_REDIRECT_SLASH = 1;
723724

724-
725725
/// A search tree.
726726
class Trie
727727
{
@@ -1530,11 +1530,12 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15301530
CatchallRule& get_catch_all(const routing_handle_result& found) {
15311531
std::vector<Blueprint*> bps_found;
15321532
get_found_bp(found.blueprint_indices, blueprints_, bps_found);
1533-
for (int i = bps_found.size() - 1; i > 0; i--)
1534-
{
1535-
std::vector<size_t> bpi = found.blueprint_indices;
1536-
if (bps_found[i]->catchall_rule().has_handler()) {
1537-
return bps_found[i]->catchall_rule();
1533+
if (!bps_found.empty()) {
1534+
for (size_t i = bps_found.size() - 1; i > 0; i--)
1535+
{
1536+
if (bps_found[i]->catchall_rule().has_handler()) {
1537+
return bps_found[i]->catchall_rule();
1538+
}
15381539
}
15391540
}
15401541
return catchall_rule_;
@@ -1546,20 +1547,17 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15461547

15471548
std::vector<Blueprint*> bps_found;
15481549
get_found_bp(found.blueprint_indices, blueprints_, bps_found);
1549-
for (int i = bps_found.size() - 1; i > 0; i--)
1550-
{
1551-
std::vector<size_t> bpi = found.blueprint_indices;
1552-
if (bps_found[i]->catchall_rule().has_handler())
1553-
{
1550+
if (!bps_found.empty()) {
1551+
for (size_t i = bps_found.size() - 1; i > 0; i--) {
1552+
if (bps_found[i]->catchall_rule().has_handler()) {
15541553
#ifdef CROW_ENABLE_DEBUG
1555-
return std::string("Redirected to Blueprint \"" + bps_found[i]->prefix() + "\" Catchall rule");
1554+
return std::string("Redirected to Blueprint \"" + bps_found[i]->prefix() + "\" Catchall rule");
15561555
#else
1557-
return EMPTY;
1556+
return EMPTY;
15581557
#endif
1558+
}
15591559
}
1560-
}
1561-
if (catchall_rule_.has_handler())
1562-
{
1560+
} else if (catchall_rule_.has_handler()) {
15631561
#ifdef CROW_ENABLE_DEBUG
15641562
return std::string("Redirected to global Catchall rule");
15651563
#else

0 commit comments

Comments
 (0)