summaryrefslogtreecommitdiffstats
path: root/src/restore.c
diff options
context:
space:
mode:
authorGravatar Comtea042026-10-05 11:44:56 +0900
committerGravatar Nikias Bassen2026-11-27 02:46:05 +0100
commitb7a23759cb0016d4782a44368ba775f197489f69 (patch)
tree8c268662accf9255338588913763b50c5b5cce7c /src/restore.c
parent5adea9ba8c08dd406d9fc833612859ecedfaf5ec (diff)
downloadidevicerestore-b7a23759cb0016d4782a44368ba775f197489f69.tar.gz
idevicerestore-b7a23759cb0016d4782a44368ba775f197489f69.tar.bz2
Handle realloc() failure in curl write callbacks
download_write_buffer_callback() and _curl_write_callback() assigned the result of realloc() directly to response->content, so on out-of-memory the data received so far was leaked and the following memcpy() wrote through a NULL pointer. Keep the existing buffer on failure and return 0 so that curl aborts the transfer with CURLE_WRITE_ERROR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/restore.c')
-rw-r--r--src/restore.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/restore.c b/src/restore.c
index a69c581..e220598 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -1333,7 +1333,12 @@ static size_t _curl_write_callback(char* data, size_t size, size_t nmemb, query_
{
size_t total = size * nmemb;
if (total != 0) {
- response->content = realloc(response->content, response->length + total + 1);
+ char* new_content = realloc(response->content, response->length + total + 1);
+ if (!new_content) {
+ /* keep the data received so far; returning a short count makes curl abort the transfer */
+ return 0;
+ }
+ response->content = new_content;
memcpy(response->content + response->length, data, total);
response->content[response->length + total] = '\0';
response->length += total;