@@ -92,7 +92,7 @@ static int _search_ota_candidate_from_cache(uint16_t vendor_id, uint16_t product
9292
9393static size_t _find_empty_ota_candidates ()
9494{
95- uint8_t oldest_candidate_lifetime = 0 ;
95+ uint32_t oldest_candidate_lifetime = 0 ;
9696 size_t oldest_candidate_index = 0 ;
9797 for (size_t index = 0 ; index < max_ota_candidate_count; ++index) {
9898 if (!_ota_candidates_cache[index]) {
@@ -160,11 +160,9 @@ static esp_err_t _query_software_version_array(const uint16_t vendor_id, const u
160160 http_payload.Calloc (1024 );
161161 if ((http_len > 0 ) && (http_status_code == 200 )) {
162162 ESP_GOTO_ON_FALSE (http_payload.Get (), ESP_ERR_NO_MEM , close, TAG , " Failed to alloc memory for http_payload" );
163- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
164- http_payload[http_len] = ' \0 ' ;
163+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
165164 } else {
166- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
167- http_payload[http_len] = ' \0 ' ;
165+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
168166 ESP_LOGE (TAG , " Invalid response for %s" , url);
169167 ESP_LOGE (TAG , " Status = %d, Data = %s" , http_status_code, http_len > 0 ? http_payload.Get () : " None" );
170168 ret = ESP_FAIL ;
@@ -253,11 +251,9 @@ static esp_err_t _query_ota_candidate(model_version_t *model, uint32_t new_softw
253251 http_payload.Calloc (1024 );
254252 if ((http_len > 0 ) && (http_status_code == 200 )) {
255253 ESP_GOTO_ON_FALSE (http_payload.Get (), ESP_ERR_NO_MEM , close, TAG , " Failed to alloc memory for http_payload" );
256- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
257- http_payload[http_len] = ' \0 ' ;
254+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
258255 } else {
259- http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize ());
260- http_payload[http_len] = ' \0 ' ;
256+ http_len = esp_http_client_read_response (client, http_payload.Get (), http_payload.AllocatedSize () - 1 );
261257 ESP_LOGE (TAG , " Invalid response for %s" , url);
262258 ESP_LOGE (TAG , " Status = %d, Data = %s" , http_status_code, http_len > 0 ? http_payload.Get () : " None" );
263259 ret = ESP_FAIL ;
@@ -290,6 +286,9 @@ static esp_err_t _query_ota_candidate(model_version_t *model, uint32_t new_softw
290286 }
291287 if (json_obj_get_strlen (&jctx, " otaUrl" , &string_len) == 0 &&
292288 json_obj_get_string (&jctx, " otaUrl" , model->ota_url , sizeof (model->ota_url )) == 0 ) {
289+ string_len = string_len < sizeof (model->ota_url ) - 1
290+ ? string_len
291+ : sizeof (model->ota_url ) - 1 ;
293292 model->ota_url [string_len] = 0 ;
294293 }
295294 } else {
0 commit comments