diff --git a/doc/Changelog.md b/doc/Changelog.md index 42d7dca..621ed82 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -2,6 +2,9 @@ # git master +* [192](https://github.com/HBPVIS/ZeroEQ/pull/192): + Fix HTTP server segfault when registering an empty endpoint, throw an + exception instead. * [190](https://github.com/HBPVIS/ZeroEQ/pull/190): Fix HTTP server segfault when accessing the root element (GET '/'). * [189](https://github.com/HBPVIS/ZeroEQ/pull/189): diff --git a/tests/http/server.cpp b/tests/http/server.cpp index 288ffe6..f8f1ee3 100644 --- a/tests/http/server.cpp +++ b/tests/http/server.cpp @@ -639,6 +639,13 @@ BOOST_AUTO_TEST_CASE(event_registry_name) zeroeq::PUTFunc( [] { return true; } )), std::runtime_error ); + BOOST_CHECK_THROW( server.handleGET( "", + zeroeq::GETFunc( [] { return std::string(); } )), + std::runtime_error ); + BOOST_CHECK_THROW( server.handlePUT( "", + zeroeq::PUTFunc( [] { return true; } )), + std::runtime_error ); + BOOST_CHECK( server.handleGET( "foo/registry", zeroeq::GETFunc( [] { return std::string( "bar" ); } ))); BOOST_CHECK( server.handlePUT( "foo/registry", diff --git a/zeroeq/http/server.cpp b/zeroeq/http/server.cpp index e855c47..b29c8c9 100644 --- a/zeroeq/http/server.cpp +++ b/zeroeq/http/server.cpp @@ -27,6 +27,9 @@ namespace // Inspiration: https://gist.github.com/rodamber/2558e25d4d8f6b9f2ffdf7bd49471340 std::string _camelCaseToHyphenated( std::string camelCase ) { + if( camelCase.empty( )) + return camelCase; + std::string str( 1, tolower(camelCase[0]) ); for( auto it = camelCase.begin() + 1; it != camelCase.end(); ++it ) { @@ -151,6 +154,9 @@ class Server::Impl : public detail::Sender bool handlePUT( std::string endpoint, const std::string& schema, const PUTPayloadFunc& func ) { + if( endpoint.empty( )) + ZEROEQTHROW( std::runtime_error( "endpoint name cannot be empty" )); + _convertEndpointName( endpoint ); if( endpoint == REQUEST_REGISTRY ) ZEROEQTHROW( std::runtime_error( @@ -181,6 +187,8 @@ class Server::Impl : public detail::Sender bool handleGET( std::string endpoint, const std::string& schema, const GETFunc& func ) { + if( endpoint.empty( )) + ZEROEQTHROW( std::runtime_error( "endpoint name cannot be empty" )); _convertEndpointName( endpoint ); if( endpoint == REQUEST_REGISTRY )