Skip to content

Commit

Permalink
fix(server): crash if remove not existing route
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler92 committed Apr 27, 2024
1 parent 769c0c3 commit 8bd3683
Show file tree
Hide file tree
Showing 24 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/

Files: tests/fuzzers/corpus/http-*.txt
Files: tests/fuzzers/corpus/*
Copyright: 2024 Mikhail Khachayants
License: Apache-2.0

2 changes: 2 additions & 0 deletions src/server/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ namespace Pistache::Rest
collection = &optional_;
break;
case SegmentType::Splat:
if (!splat_)
throw std::runtime_error("Requested route does not exist.");
return splat_->removeRoute(lower_path);
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S*/apiR
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/fuzzers/fuzz_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void fuzz_router(const std::string& input)
});
break;
case 'R':
// ignoreExceptions([&] { tree.removeRoute(path); });
ignoreExceptions([&] { tree.removeRoute(path); });
break;
case 'F':
ignoreExceptions([&] { tree.findRoute(path); });
Expand Down
11 changes: 11 additions & 0 deletions tests/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ TEST(router_test, test_route_head_request)
endpoint->shutdown();
}

TEST(router_test, test_remove_not_existing)
{
SegmentTreeNode routes;

ASSERT_THROW(routes.removeRoute("/v1/hello"), std::runtime_error);
ASSERT_THROW(routes.removeRoute("/v1/hello/:name/"), std::runtime_error);
ASSERT_THROW(routes.removeRoute("/get/:key?/bar"), std::runtime_error);
ASSERT_THROW(routes.removeRoute("/say/*/to/*"), std::runtime_error);
ASSERT_THROW(routes.removeRoute("*/api"), std::runtime_error);
}

class MyHandler
{
public:
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.9.20240421
0.2.9.20240427

0 comments on commit 8bd3683

Please sign in to comment.