Skip to content

Commit

Permalink
day_ahead_prices: Further improve json buffer safety
Browse files Browse the repository at this point in the history
  • Loading branch information
borg42 committed Nov 16, 2024
1 parent 4994ef3 commit 9a109d4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions software/src/modules/day_ahead_prices/day_ahead_prices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,15 @@ void DayAheadPrices::update()
break;

case AsyncHTTPSClientEventType::Finished:
json_buffer[json_buffer_position] = '\0';
handle_new_data();
if(json_buffer == nullptr) {
logger.printfln("JSON Buffer was not allocated correctly");

download_state = DAP_DOWNLOAD_STATE_ERROR;
break;
} else {
json_buffer[json_buffer_position] = '\0';
handle_new_data();
}
handle_cleanup();

if (download_state == DAP_DOWNLOAD_STATE_PENDING) {
Expand All @@ -318,7 +325,9 @@ void DayAheadPrices::update()

void DayAheadPrices::handle_cleanup()
{
heap_caps_free(json_buffer);
if (json_buffer != nullptr) {
heap_caps_free(json_buffer);
}
json_buffer = nullptr;
json_buffer_position = 0;
}
Expand Down

0 comments on commit 9a109d4

Please sign in to comment.