Skip to content

[BUG] unpredictable results in file_response with filename pointing into the void #255

@LeSpocky

Description

@LeSpocky

Prerequisites

Description

When creating an object of class httpserver::file_response with a filename not related to an actually existing file, the behavior of the application is more or less unpredictable depending on which version of libmicrohttpd is used. We saw HTTP responses with status 200 and an empty data part, but the app might as well segfault.

Steps to Reproduce

  1. Create an instance of class httpserver::file_response with a filename pointing to a non existent file
  2. Use that object as a response for an actual request

Expected behavior: webserver returns a sensible HTTP status code like 500 (Internal Server Error) or better 404 (Not Found).

Actual behavior: webserver crashes (segfault), does not answer, or even returns code passed to constructor of file_response

Reproduces how often: always

Versions

  • OS version
    • Debian GNU/Linux 10 (buster)
    • custom built embedded firmware
  • libhttpserver version: master, self compiled
  • libmicrohttpd version: multiple self compiled from v0.9.53 up to v0.9.73

If you have problems during build: build is fine

Additional Information

What happens is httpserver::file_response::get_raw_response() might return a nullptr which is then passed on to http_response::decorate_response() which itself calls some libmicrohttpd functions like MHD_add_response_header() or MHD_add_response_footer() which might or might not crash depending on version.

Will show a unit test reproducing this.

Metadata

Metadata

Assignees

Labels

bugConfirmed bugs or reports that are very likely to be bugs.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions