-
Notifications
You must be signed in to change notification settings - Fork 91
My first change #1409
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
Open
yazdan-iot
wants to merge
6
commits into
FujiNetWIFI:master
Choose a base branch
from
yazdan-iot:my-first-change
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
My first change #1409
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed48071
First Commit
abolfazl33369 ee670ea
Fix: check malloc() result in fnHttpClient to prevent null pointer crash
yazdan-iot 478fbd3
Remove accidental test text from README
yazdan-iot 37718b3
Fix 7 bugs in lib/http/
yazdan-iot 0f9c1fc
Use strlcpy instead of strncpy for null termination
yazdan-iot e19196e
Add compat_string.h include for strlcpy
yazdan-iot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,10 @@ const char *webdav_depths[] = {"0", "1", "infinity"}; | |
| fnHttpClient::fnHttpClient() | ||
| { | ||
| _buffer = (char *)malloc(DEFAULT_HTTP_BUF_SIZE); | ||
| if (_buffer == nullptr) | ||
| { | ||
| Debug_printf("fnHttpClient::fnHttpClient() failed to allocate %d byte buffer\r\n", DEFAULT_HTTP_BUF_SIZE); | ||
| } | ||
| } | ||
|
|
||
| // Close connection, destroy any resoruces | ||
|
|
@@ -293,7 +297,7 @@ esp_err_t fnHttpClient::_httpevent_handler(esp_http_client_event_t *evt) | |
| Debug_printf("HTTP_EVENT_ON_HEADER %u\r\n", uxTaskGetStackHighWaterMark(nullptr)); | ||
| #endif | ||
| // Check to see if we should store this response header | ||
| if (client->_stored_headers.size() <= 0) | ||
| if (client->_stored_headers.size() == 0) | ||
| break; | ||
|
|
||
| client->set_header_value(evt->header_key, evt->header_value); | ||
|
|
@@ -354,9 +358,16 @@ esp_err_t fnHttpClient::_httpevent_handler(esp_http_client_event_t *evt) | |
| Debug_printf("HTTP_EVENT_ON_DATA: Data: %p, Datalen: %d\r\n", evt->data, evt->data_len); | ||
| #endif | ||
|
|
||
| client->_buffer_pos = 0; | ||
| client->_buffer_len = (evt->data_len > DEFAULT_HTTP_BUF_SIZE) ? DEFAULT_HTTP_BUF_SIZE : evt->data_len; | ||
| memcpy(client->_buffer, evt->data, client->_buffer_len); | ||
| if (client->_buffer == nullptr) { | ||
| Debug_printf("HTTP_EVENT_ON_DATA: _buffer is null, dropping data\r\n"); | ||
| client->_buffer_pos = 0; | ||
| client->_buffer_len = 0; | ||
| } | ||
| else { | ||
| client->_buffer_pos = 0; | ||
| client->_buffer_len = (evt->data_len > DEFAULT_HTTP_BUF_SIZE) ? DEFAULT_HTTP_BUF_SIZE : evt->data_len; | ||
| memcpy(client->_buffer, evt->data, client->_buffer_len); | ||
| } | ||
|
|
||
| // Now let the reader know there's data in the buffer | ||
| xTaskNotifyGive(client->_taskh_consumer); | ||
|
|
@@ -811,7 +822,9 @@ char *fnHttpClient::get_header(int index, char *buffer, int buffer_len) | |
|
|
||
| auto vi = _stored_headers.begin(); | ||
| std::advance(vi, index); | ||
| return strncpy(buffer, vi->second.c_str(), buffer_len); | ||
| strncpy(buffer, vi->second.c_str(), buffer_len - 1); | ||
| buffer[buffer_len - 1] = '\0'; | ||
| return buffer; | ||
|
Comment on lines
-814
to
+827
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's easier to replace |
||
| } | ||
|
|
||
| const std::string fnHttpClient::get_header(int index) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -984,7 +984,7 @@ int mgHttpClient::COPY(const char *destination, bool overwrite, bool move) | |
| _flush_response(); | ||
|
|
||
| // Set method | ||
| _method = HTTP_MOVE; | ||
| _method = move ? HTTP_MOVE : HTTP_COPY; | ||
| // Set detination | ||
| set_header("Destination", destination); | ||
| // Set overwrite | ||
|
|
@@ -1110,7 +1110,9 @@ char *mgHttpClient::get_header(int index, char *buffer, int buffer_len) | |
|
|
||
| auto vi = _stored_headers.begin(); | ||
| std::advance(vi, index); | ||
| return strncpy(buffer, vi->second.c_str(), buffer_len); | ||
| strncpy(buffer, vi->second.c_str(), buffer_len - 1); | ||
| buffer[buffer_len - 1] = '\0'; | ||
| return buffer; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, just use |
||
| } | ||
|
|
||
| const std::string mgHttpClient::get_header(int index) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm pretty sure this fix is already in master. You probably need to rebase this branch on master. First go to your fork and go to your master branch and click the Sync fork button. Then from your cloned repo:
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.
ok thanks