-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Conversation
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]>
struct flb_http_client *c; | ||
|
||
|
||
header_size = str_gen_header(method, uri, host, port, proxy, flags, NULL, 0); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
ping on comments. |
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. |
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:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
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.