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
- Create an instance of class
httpserver::file_response with a filename pointing to a non existent file
- 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.
Prerequisites
Description
When creating an object of class
httpserver::file_responsewith afilenamenot 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
httpserver::file_responsewith afilenamepointing to a non existent fileExpected 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_responseReproduces how often: always
Versions
If you have problems during build: build is fine
Additional Information
What happens is
httpserver::file_response::get_raw_response()might return anullptrwhich is then passed on tohttp_response::decorate_response()which itself calls some libmicrohttpd functions likeMHD_add_response_header()orMHD_add_response_footer()which might or might not crash depending on version.Will show a unit test reproducing this.