Skip to content

Commit

Permalink
Merge branch 'fix/esp_partition_write_datatype_overflow' into 'master'
Browse files Browse the repository at this point in the history
fix(esp_partition): fix data type overflow sanity check

See merge request espressif/esp-idf!31348
  • Loading branch information
RathiSonika committed Jul 8, 2024
2 parents ba55aed + a81f576 commit b9965fe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions components/esp_partition/partition_target.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -30,7 +30,7 @@ esp_err_t esp_partition_read(const esp_partition_t *partition,
if (src_offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (src_offset + size > partition->size) {
if (size > partition->size - src_offset) {
return ESP_ERR_INVALID_SIZE;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ esp_err_t esp_partition_write(const esp_partition_t *partition,
if (dst_offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (dst_offset + size > partition->size) {
if (size > partition->size - dst_offset) {
return ESP_ERR_INVALID_SIZE;
}
dst_offset = partition->address + dst_offset;
Expand All @@ -95,7 +95,7 @@ esp_err_t esp_partition_read_raw(const esp_partition_t *partition,
if (src_offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (src_offset + size > partition->size) {
if (size > partition->size - src_offset) {
return ESP_ERR_INVALID_SIZE;
}

Expand All @@ -112,7 +112,7 @@ esp_err_t esp_partition_write_raw(const esp_partition_t *partition,
if (dst_offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (dst_offset + size > partition->size) {
if (size > partition->size - dst_offset) {
return ESP_ERR_INVALID_SIZE;
}
dst_offset = partition->address + dst_offset;
Expand All @@ -130,7 +130,7 @@ esp_err_t esp_partition_erase_range(const esp_partition_t *partition,
if (offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (offset + size > partition->size) {
if (size > partition->size - offset) {
return ESP_ERR_INVALID_SIZE;
}
if (size % SPI_FLASH_SEC_SIZE != 0) {
Expand Down Expand Up @@ -159,7 +159,7 @@ esp_err_t esp_partition_mmap(const esp_partition_t *partition, size_t offset, si
if (offset > partition->size) {
return ESP_ERR_INVALID_ARG;
}
if (offset + size > partition->size) {
if (size > partition->size - offset) {
return ESP_ERR_INVALID_SIZE;
}
if (partition->flash_chip != esp_flash_default_chip) {
Expand Down

0 comments on commit b9965fe

Please # to comment.