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

[BUG] Segfault at runtime when passing nullptr on resource register #265

Open
1 task done
LeSpocky opened this issue Mar 24, 2022 · 0 comments
Open
1 task done
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs.

Comments

@LeSpocky
Copy link
Contributor

Prerequisites

Description

When passing a nullptr as second argument (http_resource* hrm) to webserver::register_resource() the application will segfault at runtime.

Steps to Reproduce

  1. declare a std::unique_ptr to a class derived from httpserver::http_resource
  2. forget to reset/initialize that ptr
  3. pass it to httpserver::webserver::register_resource() the usual way
  4. send a request to the webserver on that resource

Expected behavior: not sure, maybe some kind of parameter check by httpserver::webserver::register_resource()

Actual behavior: the webserver crashes with segfault at runtime

Reproduces how often: always

Versions

  • OS version: Debian GNU/Linux 10 (buster)
  • libhttpserver version: master
  • libmicrohttpd version: unknown

Additional Information

class file_response_resource : public httpserver::http_resource {
public:
	file_response_resource( std::string filename ) : filename(filename) {
		printf( "file_response resource created with filename: %s",
					 filename.c_str() );
	};

	const std::shared_ptr<httpserver::http_response> render_GET(
			const httpserver::http_request& );
private:
	std::string filename;
};

const std::shared_ptr<httpserver::http_response> file_response_resource::render_GET(
	const httpserver::http_request& )
{
	return std::shared_ptr<httpserver::file_response>(
			new httpserver::file_response(filename, 200, "text/plain") );
}

int main( int argc, char *argv[] )
{
	httpserver::webserver ws = httpserver::create_webserver(8080);
	std::unique_ptr<file_response_resource> frr;

	// forget to init frr here
	// frr.reset(new file_response_resource(argv[1]));

	// accidentally pass a nullptr here
	ws.register_resource("/file", frr.get(), true);
	ws.start(true);

	return 0;
}
@LeSpocky LeSpocky added the bug Confirmed bugs or reports that are very likely to be bugs. label Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

2 participants