@@ -91,7 +91,7 @@ static int _search_ota_candidate_from_cache(uint16_t vendor_id, uint16_t product
9191
9292static size_t _find_empty_ota_candidates ()
9393{
94- uint8_t oldest_candidate_lifetime = 0 ;
94+ uint32_t oldest_candidate_lifetime = 0 ;
9595 size_t oldest_candidate_index = 0 ;
9696 for (size_t index = 0 ; index < max_ota_candidate_count; ++index) {
9797 if (!_ota_candidates_cache[index]) {
@@ -159,11 +159,9 @@ static esp_err_t _query_software_version_array(const uint16_t vendor_id, const u
159159 http_payload.Calloc (1024 );
160160 if ((http_len > 0 ) && (http_status_code == 200 )) {
161161 ESP_GOTO_ON_FALSE (http_payload.Get (), ESP_ERR_NO_MEM , close, TAG , " Failed to alloc memory for http_payload" );
162- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
163- http_payload[http_len] = ' \0 ' ;
162+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
164163 } else {
165- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
166- http_payload[http_len] = ' \0 ' ;
164+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
167165 ESP_LOGE (TAG , " Invalid response for %s" , url);
168166 ESP_LOGE (TAG , " Status = %d, Data = %s" , http_status_code, http_len > 0 ? http_payload.Get () : " None" );
169167 ret = ESP_FAIL ;
@@ -252,11 +250,9 @@ static esp_err_t _query_ota_candidate(model_version_t *model, uint32_t new_softw
252250 http_payload.Calloc (1024 );
253251 if ((http_len > 0 ) && (http_status_code == 200 )) {
254252 ESP_GOTO_ON_FALSE (http_payload.Get (), ESP_ERR_NO_MEM , close, TAG , " Failed to alloc memory for http_payload" );
255- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
256- http_payload[http_len] = ' \0 ' ;
253+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
257254 } else {
258- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
259- http_payload[http_len] = ' \0 ' ;
255+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
260256 ESP_LOGE (TAG , " Invalid response for %s" , url);
261257 ESP_LOGE (TAG , " Status = %d, Data = %s" , http_status_code, http_len > 0 ? http_payload.Get () : " None" );
262258 ret = ESP_FAIL ;
@@ -289,6 +285,9 @@ static esp_err_t _query_ota_candidate(model_version_t *model, uint32_t new_softw
289285 }
290286 if (json_obj_get_strlen (&jctx, " otaUrl" , &string_len) == 0 &&
291287 json_obj_get_string (&jctx, " otaUrl" , model->ota_url , sizeof (model->ota_url )) == 0 ) {
288+ string_len = string_len < sizeof (model->ota_url ) - 1
289+ ? string_len
290+ : sizeof (model->ota_url ) - 1 ;
292291 model->ota_url [string_len] = 0 ;
293292 }
294293 } else {
0 commit comments