Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HTTP server segfault when registering an empty endpoint #192

Merged
merged 1 commit into from Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/Changelog.md
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions tests/http/server.cpp
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions zeroeq/http/server.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 )
Expand Down