From 8bd368347b26e1b2c5d905e29bc53a3840e1dea1 Mon Sep 17 00:00:00 2001 From: Mikhail Khachayants Date: Sat, 27 Apr 2024 14:18:22 +0300 Subject: [PATCH] fix(server): crash if remove not existing route --- .reuse/dep5 | 2 +- src/server/router.cc | 2 ++ ...4.txt => 151a3cba089a89c9d1407ffe08e66f5807206d4f} | 0 ...1.txt => 1a123ecb986602e7a63ad85805ad1b0fa68d7c20} | 0 ...7.txt => 225aa589c4433f4dddf110306aeb1d7daa08d94c} | 0 ...8.txt => 2d8d49508cc1400610e846490e092f5b42b7798b} | 0 ...1.txt => 337a82e18ae0918c54607da0510111ecae14c5af} | 0 ...7.txt => 3d744c1c4d7c10bd34b2ffc53104b736059d629e} | 0 ...5.txt => 6a632298ac9ea6e05267892d3eb608e0c06d9759} | 0 ...2.txt => 746dbfb89b36785075b80569064a1654be613f47} | 0 ...4.txt => 75952bb79d780fafa553c1a0bdddc9629cef88f2} | 0 ...5.txt => 8165d5b7e7fe7c2952955c6618565316649c38c2} | 0 ...6.txt => 83e59c3a4c183f1f88678605e15da3aa568e3b59} | 0 ...0.txt => 96607ea4447e4d6c28b00990ddec0ee0500955b5} | 0 ...9.txt => abfa7b63b7e37a2d992b53c76b7785c1af6ac595} | 0 ...8.txt => ac5f7a18fa9411453d5bd02978f667d7414876bf} | 0 .../corpus/ad71f85838f68e0779de86398faa910d2ce0b229 | 1 + ...3.txt => d7e60042b9c7b4bb905fa6eef2ae3609413dd046} | 0 ...3.txt => f0c1aa1b78c96efd2b4e57f989c631b373333791} | 0 ...6.txt => f95881a2e895c9f007152c6c84e7b3d399c24a65} | 0 ...2.txt => fd57d162e86cdf4ca56f780a8280d5e5aa327b58} | 0 tests/fuzzers/fuzz_parser.cpp | 2 +- tests/router_test.cc | 11 +++++++++++ version.txt | 2 +- 24 files changed, 17 insertions(+), 3 deletions(-) rename tests/fuzzers/corpus/{http-14.txt => 151a3cba089a89c9d1407ffe08e66f5807206d4f} (100%) rename tests/fuzzers/corpus/{http-1.txt => 1a123ecb986602e7a63ad85805ad1b0fa68d7c20} (100%) rename tests/fuzzers/corpus/{http-17.txt => 225aa589c4433f4dddf110306aeb1d7daa08d94c} (100%) rename tests/fuzzers/corpus/{http-18.txt => 2d8d49508cc1400610e846490e092f5b42b7798b} (100%) rename tests/fuzzers/corpus/{http-11.txt => 337a82e18ae0918c54607da0510111ecae14c5af} (100%) rename tests/fuzzers/corpus/{http-7.txt => 3d744c1c4d7c10bd34b2ffc53104b736059d629e} (100%) rename tests/fuzzers/corpus/{http-15.txt => 6a632298ac9ea6e05267892d3eb608e0c06d9759} (100%) rename tests/fuzzers/corpus/{http-12.txt => 746dbfb89b36785075b80569064a1654be613f47} (100%) rename tests/fuzzers/corpus/{http-4.txt => 75952bb79d780fafa553c1a0bdddc9629cef88f2} (100%) rename tests/fuzzers/corpus/{http-5.txt => 8165d5b7e7fe7c2952955c6618565316649c38c2} (100%) rename tests/fuzzers/corpus/{http-6.txt => 83e59c3a4c183f1f88678605e15da3aa568e3b59} (100%) rename tests/fuzzers/corpus/{http-10.txt => 96607ea4447e4d6c28b00990ddec0ee0500955b5} (100%) rename tests/fuzzers/corpus/{http-9.txt => abfa7b63b7e37a2d992b53c76b7785c1af6ac595} (100%) rename tests/fuzzers/corpus/{http-8.txt => ac5f7a18fa9411453d5bd02978f667d7414876bf} (100%) create mode 100644 tests/fuzzers/corpus/ad71f85838f68e0779de86398faa910d2ce0b229 rename tests/fuzzers/corpus/{http-13.txt => d7e60042b9c7b4bb905fa6eef2ae3609413dd046} (100%) rename tests/fuzzers/corpus/{http-3.txt => f0c1aa1b78c96efd2b4e57f989c631b373333791} (100%) rename tests/fuzzers/corpus/{http-16.txt => f95881a2e895c9f007152c6c84e7b3d399c24a65} (100%) rename tests/fuzzers/corpus/{http-2.txt => fd57d162e86cdf4ca56f780a8280d5e5aa327b58} (100%) diff --git a/.reuse/dep5 b/.reuse/dep5 index 0f13129a8..7ef2733a1 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -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 diff --git a/src/server/router.cc b/src/server/router.cc index 9ce168d13..79514a698 100644 --- a/src/server/router.cc +++ b/src/server/router.cc @@ -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); } diff --git a/tests/fuzzers/corpus/http-14.txt b/tests/fuzzers/corpus/151a3cba089a89c9d1407ffe08e66f5807206d4f similarity index 100% rename from tests/fuzzers/corpus/http-14.txt rename to tests/fuzzers/corpus/151a3cba089a89c9d1407ffe08e66f5807206d4f diff --git a/tests/fuzzers/corpus/http-1.txt b/tests/fuzzers/corpus/1a123ecb986602e7a63ad85805ad1b0fa68d7c20 similarity index 100% rename from tests/fuzzers/corpus/http-1.txt rename to tests/fuzzers/corpus/1a123ecb986602e7a63ad85805ad1b0fa68d7c20 diff --git a/tests/fuzzers/corpus/http-17.txt b/tests/fuzzers/corpus/225aa589c4433f4dddf110306aeb1d7daa08d94c similarity index 100% rename from tests/fuzzers/corpus/http-17.txt rename to tests/fuzzers/corpus/225aa589c4433f4dddf110306aeb1d7daa08d94c diff --git a/tests/fuzzers/corpus/http-18.txt b/tests/fuzzers/corpus/2d8d49508cc1400610e846490e092f5b42b7798b similarity index 100% rename from tests/fuzzers/corpus/http-18.txt rename to tests/fuzzers/corpus/2d8d49508cc1400610e846490e092f5b42b7798b diff --git a/tests/fuzzers/corpus/http-11.txt b/tests/fuzzers/corpus/337a82e18ae0918c54607da0510111ecae14c5af similarity index 100% rename from tests/fuzzers/corpus/http-11.txt rename to tests/fuzzers/corpus/337a82e18ae0918c54607da0510111ecae14c5af diff --git a/tests/fuzzers/corpus/http-7.txt b/tests/fuzzers/corpus/3d744c1c4d7c10bd34b2ffc53104b736059d629e similarity index 100% rename from tests/fuzzers/corpus/http-7.txt rename to tests/fuzzers/corpus/3d744c1c4d7c10bd34b2ffc53104b736059d629e diff --git a/tests/fuzzers/corpus/http-15.txt b/tests/fuzzers/corpus/6a632298ac9ea6e05267892d3eb608e0c06d9759 similarity index 100% rename from tests/fuzzers/corpus/http-15.txt rename to tests/fuzzers/corpus/6a632298ac9ea6e05267892d3eb608e0c06d9759 diff --git a/tests/fuzzers/corpus/http-12.txt b/tests/fuzzers/corpus/746dbfb89b36785075b80569064a1654be613f47 similarity index 100% rename from tests/fuzzers/corpus/http-12.txt rename to tests/fuzzers/corpus/746dbfb89b36785075b80569064a1654be613f47 diff --git a/tests/fuzzers/corpus/http-4.txt b/tests/fuzzers/corpus/75952bb79d780fafa553c1a0bdddc9629cef88f2 similarity index 100% rename from tests/fuzzers/corpus/http-4.txt rename to tests/fuzzers/corpus/75952bb79d780fafa553c1a0bdddc9629cef88f2 diff --git a/tests/fuzzers/corpus/http-5.txt b/tests/fuzzers/corpus/8165d5b7e7fe7c2952955c6618565316649c38c2 similarity index 100% rename from tests/fuzzers/corpus/http-5.txt rename to tests/fuzzers/corpus/8165d5b7e7fe7c2952955c6618565316649c38c2 diff --git a/tests/fuzzers/corpus/http-6.txt b/tests/fuzzers/corpus/83e59c3a4c183f1f88678605e15da3aa568e3b59 similarity index 100% rename from tests/fuzzers/corpus/http-6.txt rename to tests/fuzzers/corpus/83e59c3a4c183f1f88678605e15da3aa568e3b59 diff --git a/tests/fuzzers/corpus/http-10.txt b/tests/fuzzers/corpus/96607ea4447e4d6c28b00990ddec0ee0500955b5 similarity index 100% rename from tests/fuzzers/corpus/http-10.txt rename to tests/fuzzers/corpus/96607ea4447e4d6c28b00990ddec0ee0500955b5 diff --git a/tests/fuzzers/corpus/http-9.txt b/tests/fuzzers/corpus/abfa7b63b7e37a2d992b53c76b7785c1af6ac595 similarity index 100% rename from tests/fuzzers/corpus/http-9.txt rename to tests/fuzzers/corpus/abfa7b63b7e37a2d992b53c76b7785c1af6ac595 diff --git a/tests/fuzzers/corpus/http-8.txt b/tests/fuzzers/corpus/ac5f7a18fa9411453d5bd02978f667d7414876bf similarity index 100% rename from tests/fuzzers/corpus/http-8.txt rename to tests/fuzzers/corpus/ac5f7a18fa9411453d5bd02978f667d7414876bf diff --git a/tests/fuzzers/corpus/ad71f85838f68e0779de86398faa910d2ce0b229 b/tests/fuzzers/corpus/ad71f85838f68e0779de86398faa910d2ce0b229 new file mode 100644 index 000000000..ec5af4996 --- /dev/null +++ b/tests/fuzzers/corpus/ad71f85838f68e0779de86398faa910d2ce0b229 @@ -0,0 +1 @@ +S*/apiR diff --git a/tests/fuzzers/corpus/http-13.txt b/tests/fuzzers/corpus/d7e60042b9c7b4bb905fa6eef2ae3609413dd046 similarity index 100% rename from tests/fuzzers/corpus/http-13.txt rename to tests/fuzzers/corpus/d7e60042b9c7b4bb905fa6eef2ae3609413dd046 diff --git a/tests/fuzzers/corpus/http-3.txt b/tests/fuzzers/corpus/f0c1aa1b78c96efd2b4e57f989c631b373333791 similarity index 100% rename from tests/fuzzers/corpus/http-3.txt rename to tests/fuzzers/corpus/f0c1aa1b78c96efd2b4e57f989c631b373333791 diff --git a/tests/fuzzers/corpus/http-16.txt b/tests/fuzzers/corpus/f95881a2e895c9f007152c6c84e7b3d399c24a65 similarity index 100% rename from tests/fuzzers/corpus/http-16.txt rename to tests/fuzzers/corpus/f95881a2e895c9f007152c6c84e7b3d399c24a65 diff --git a/tests/fuzzers/corpus/http-2.txt b/tests/fuzzers/corpus/fd57d162e86cdf4ca56f780a8280d5e5aa327b58 similarity index 100% rename from tests/fuzzers/corpus/http-2.txt rename to tests/fuzzers/corpus/fd57d162e86cdf4ca56f780a8280d5e5aa327b58 diff --git a/tests/fuzzers/fuzz_parser.cpp b/tests/fuzzers/fuzz_parser.cpp index 78721c28d..c3e984ee9 100644 --- a/tests/fuzzers/fuzz_parser.cpp +++ b/tests/fuzzers/fuzz_parser.cpp @@ -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); }); diff --git a/tests/router_test.cc b/tests/router_test.cc index 3a6d8f986..82674f7d4 100644 --- a/tests/router_test.cc +++ b/tests/router_test.cc @@ -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: diff --git a/version.txt b/version.txt index f7894639b..24c561501 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.2.9.20240421 +0.2.9.20240427