Skip to content

Commit

Permalink
Merge pull request #727 from DrHazemAli/main
Browse files Browse the repository at this point in the history
Fix memory overflow and capacity regression.
  • Loading branch information
pabuhler authored Nov 14, 2024
2 parents 3c0b0f9 + 63f774d commit f8bf8af
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4898,9 +4898,9 @@ srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list,
if (list->size == list->capacity) {
size_t new_capacity = list->capacity * 2;

// check for capacity overflow.
if ((sizeof(list_entry) * new_capacity) <=
(sizeof(list_entry) * list->capacity)) {
// Check for capacity overflow.
if (new_capacity < list->capacity ||
new_capacity > SIZE_MAX / sizeof(list_entry)) {
return srtp_err_status_alloc_fail;
}

Expand All @@ -4910,13 +4910,16 @@ srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list,
return srtp_err_status_alloc_fail;
}

// copy previous entries into the new buffer
// Copy previous entries into the new buffer.
memcpy(new_entries, list->entries, sizeof(list_entry) * list->capacity);
// release previous entries

// Release previous entries.
srtp_crypto_free(list->entries);
// assign new entries to the list

// Assign new entries to the list.
list->entries = new_entries;
// update list capacity

// Update list capacity.
list->capacity = new_capacity;
}

Expand Down

0 comments on commit f8bf8af

Please sign in to comment.