10000 write_http no longer writes http response to stdout by duckfez · Pull Request #3263 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

write_http no longer writes http response to stdout #3263

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

Merged
merged 5 commits into from
Jun 6, 2020

Conversation

duckfez
Copy link
Contributor
@duckfez duckfez commented Aug 22, 2019

Should fix #3105. Replaces PR #3257.

Registers a callback with libcurl to write the HTTP response to a buffer instead of stdout. Depending on logging settings, this will either be discarded or written to the log. By design, I'm only keeping the first 4K of the HTTP response, as any additional data is probably not helpful. Tested with Splunk HEC, and seems to work there - not tested with other HTTP targets.

ChangeLog: write_http: Remove libcurl default HTTP response to stdout

src/write_http.c Outdated
@@ -807,6 +845,16 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */
wh_callback_free(cb);
return -1;
}

cb->response_buffer_size = WRITE_HTTP_RESPONSE_BUFFER_SIZE;
cb->response_buffer = malloc(cb->response_buffer_size);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not make response_buffer as array of given size, its length seems to be fixed anyway? It would simplify things in other places too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would be fine. It's been a while, but I think I was originally trying for being able to grow the response_buffer dynamically if the response coming back wouldn't fit. I gave up, realizing that for most use cases the first few hundred bytes of the response are all that they need, and even then only in the case of an error.

I also thought about trying to allocate a response buffer as big as the Content-Length header, but I don't think that value is necessarily available to me here.

src/write_http.c Outdated
len = nmemb;

memcpy(cb->response_buffer, ptr, len);
cb->response_buffer[cb->response_buffer_size] = '\0';
Copy link
Contributor
@dago dago Feb 25, 2020

Choose a reason for hiding this comment

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

This produces a memory corruption as it writes the \0 past the end of the allocated storage. This should probably be

cb->response_buffer[len] = '\0';

@dago dago added Waiting for response - 1st time Waiting for contributor to respond - 1st call and removed Pending contributor action labels Feb 29, 2020
@duckfez duckfez requested a review from a team as a code owner April 5, 2020 16:19
@duckfez
Copy link
Contributor Author
duckfez commented Apr 5, 2020

Updated per suggestions made in review. The response buffer is now an array at 1K, and I've hopefully fixed the out-of-bounds accesses. My apologies it's taken so long to get this turned around.

Copy link
Member
@kwiatrox kwiatrox left a comment

Choose a reason for hiding this comment

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

LGTM

@mrunge mrunge merged commit 6b24c52 into collectd:master Jun 6, 2020
@mrunge
Copy link
Member
mrunge commented Jun 6, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for response - 1st time Waiting for contributor to respond - 1st call
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chatty messages (write_http)
4 participants
0