>From ed8acdbf66d74284d6688ad0ac69362bfdbc98a9 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Wed, 7 May 2014 22:38:20 +0200 Subject: [PATCH 1/2] Fix bugs causing memory corruption. --- src/ChangeLog | 6 ++++++ src/multi.c | 2 +- src/retr.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 537a707..55a1278 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-05-07 Jure Grabnar + + * multi.c: Add condition to fix memory corruption and downloading in parallel + in general. + * retr.c: Increase buffer size by 1 for '\0' to avoid memory corruption. + 2014-03-26 Darshit Shah * ftp.c (getftp): Rearrange parameters to fix compiler warning diff --git a/src/multi.c b/src/multi.c index 4b22b2e..43c2f73 100644 --- a/src/multi.c +++ b/src/multi.c @@ -153,7 +153,7 @@ fill_ranges_data(int num_of_resources, long long int file_size, for (r = 0; r < num_of_resources; ++r) ranges[i].resources[r] = false; ++i; - } while (ranges[i-1].last_byte < (file_size - 1)); + } while (i < opt.jobs && ranges[i-1].last_byte < (file_size - 1)); ranges[i-1].last_byte = file_size -1; return i; diff --git a/src/retr.c b/src/retr.c index 8c361de..2f45fa5 100644 --- a/src/retr.c +++ b/src/retr.c @@ -1250,7 +1250,7 @@ retrieve_from_file (const char *file, bool html, int *count) int res; /* Form the actual file to be downloaded and verify hash. */ file_path = malloc((opt.dir_prefix ? strlen(opt.dir_prefix) : 0) - + strlen(file->name) + (sizeof "/")); + + strlen(file->name) + (sizeof "/") + 1); if(opt.dir_prefix) sprintf(file_path, "%s/%s", opt.dir_prefix, file->name); else -- 1.9.2