From f6dc731a57cb162220433cc77f65999a2d5fd04d Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 7 Jan 2011 23:46:07 +0100 Subject: idevicebackup4: don't segfault if opening file for writing fails --- tools/idevicebackup4.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/idevicebackup4.c b/tools/idevicebackup4.c index c4ee847..ef3fdd0 100644 --- a/tools/idevicebackup4.c +++ b/tools/idevicebackup4.c @@ -1056,7 +1056,7 @@ static int handle_receive_files(plist_t message, const char *backup_dir) remove(bname); f = fopen(bname, "wb"); - while (code == CODE_FILE_DATA) { + while (f && (code == CODE_FILE_DATA)) { blocksize = nlen-1; bdone = 0; rlen = 0; @@ -1090,9 +1090,12 @@ static int handle_receive_files(plist_t message, const char *backup_dir) break; } } - fclose(f); - - file_count++; + if (f) { + fclose(f); + file_count++; + } else { + printf("Error opening '%s' for writing: %s\n", bname, strerror(errno)); + } if (backup_total_size > 0) print_progress(backup_real_size, backup_total_size); if (nlen == 0) { -- cgit v1.1-32-gdbae