Skip to content

[BUG] Debug print of upload_data does not consider unterminated strings #242

@LeSpocky

Description

@LeSpocky

Prerequisites

Description

Debug output fills the console with garbage, if upload_data is no terminated string, like this:

Writing content: {"login":{"pass":"config","user":"admin"}}��������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
�������������������������������

Steps to Reproduce

  1. Configure libhttpserver with --enable-debug
  2. Build libhttpserver
  3. In your app source create and hook up a resource
  4. Implement the render_POST method
  5. Run the app in foreground
  6. Send POST data to it, e.g. with curl: curl -v -H "Content-Type: application/json" -d '{"login":{"pass":"admin","user":"admin"}}' http://localhost:8888/api/v1/control/system/login
  7. Watch app output

Expected behavior: Consider upload_data_size and print only up to that length

Actual behavior: Blindly print until terminating null byte, possibly resulting in segfault

Reproduces how often: always with my application, not sure with other applications

Versions

  • OS version: Debian GNU/Linux 10 (buster)
  • libhttpserver version: 0.18.2-22-g263f2bd (current master)
  • libmicrohttpd version: 0.9.62-1 (debian package)

Additional Information

The const char *upload_data is a parameter of a libmicrohttpd callback function, type MHD_AccessHandlerCallback. When reading libmicrohttpd API doc I get no clue that string might be unterminated. Maybe raise issue over there?

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