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

http-client: fix heap overflow caused by large URLs. #7778

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Aug 1, 2023

The function flb_http_client allocates a buffer for the method, URL and headers and uses snprintf to expand the first line of the http request. When it does so it uses the ret value from snprintf as the header_len for the length of the used buffer, but snprintf returns the size it wants to create the entire string not how long the string it writes is. This can lead to a heap overflow when adding headers.

This PR fixes that by running snprintf initially without a buffer to calculate how large a buffer we actually need.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

The function flb_http_client allocates a buffer for the method, URL
and headers and uses snprintf to expand the first line of the http
request. When it does so it uses the ret value from snprintf
as the header_len for the length of the used buffer, but snprintf
returns the size it wants to create the entire string not how
long the string it writes is. This can lead to a heap overflow
when adding headers.

This PR fixes that by running snprintf initially without a
buffer to calculate how large a buffer we actually need.

Signed-off-by: Phillip Whelan <[email protected]>
@pwhelan pwhelan temporarily deployed to pr August 1, 2023 19:55 — with GitHub Actions Inactive
@pwhelan pwhelan temporarily deployed to pr August 1, 2023 19:55 — with GitHub Actions Inactive
@pwhelan pwhelan temporarily deployed to pr August 1, 2023 19:55 — with GitHub Actions Inactive
@pwhelan pwhelan temporarily deployed to pr August 1, 2023 20:21 — with GitHub Actions Inactive
struct flb_http_client *c;


header_size = str_gen_header(method, uri, host, port, proxy, flags, NULL, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you please move the composition of this string to use a flb_sds_printf() family functions ?, that will help us to get rid of size calculation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do that we loose all control over the maximum size of the URL.

@edsiper
Copy link
Member

edsiper commented Sep 23, 2023

ping on comments.

Copy link
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Dec 25, 2023
@github-actions github-actions bot removed the Stale label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants