From 6c9b82e72ac067207b1d66a3112485ad8d690f32 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 11 Jun 2011 12:50:15 -0400 Subject: dload: handle irregular URLs URLs might end with a slash and follow redirects, or could be a generated by a script such as /getpkg.php?id=12345. In both cases, we may have a better filename that we can write to, taken from either content-disposition header, or the effective URL. Specific to the first case, we write to a temporary file of the format 'alpmtmp.XXXXXX', where XXXXXX is randomized by mkstemp(3). Since this is a randomly generated file, we cannot support resuming and the file is unlinked in the event of an interrupt. We also run into the possibility of changing out the filename from under alpm on a -U operation, so callers of _alpm_download can optionally pass a pointer to a *char to be filled in by curl_download_internal with the actual filename we wrote to. Any sync operation will pass a NULL pointer here, as we rely on specific names for packages from a mirror. Fixes FS#22645. Signed-off-by: Dave Reisner --- lib/libalpm/dload.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/dload.h') diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 0cdd9001..351b2b30 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -29,11 +29,12 @@ struct fileinfo { alpm_handle_t *handle; const char *filename; + char *cd_filename; double initial_size; }; int _alpm_download(alpm_handle_t *handle, const char *url, const char *localpath, - int force, int allow_resume, int errors_ok); + char **final_file, int force, int allow_resume, int errors_ok); #endif /* _ALPM_DLOAD_H */ -- cgit v1.2.3-24-g4f1b From 6dc71926f9b16ebcf11b924941092d6eab204224 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 24 Jun 2011 00:18:01 -0400 Subject: lib/dload: prevent large file attacks This means creating a new struct which can pass more descriptive data from the back end sync functions to the downloader. In particular, we're interested in the download size read from the sync DB. When the remote server reports a size larger than this (via a content-length header), abort the transfer. In cases where the size is unknown, we set a hard upper limit of: * 25MiB for a sync DB * 16KiB for a signature For reference, 25MiB is more than twice the size of all of the current binary repos (with files) combined, and 16KiB is a truly gargantuan signature. Signed-off-by: Dave Reisner --- lib/libalpm/dload.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/libalpm/dload.h') diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 351b2b30..6a2dd392 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -33,8 +33,17 @@ struct fileinfo { double initial_size; }; -int _alpm_download(alpm_handle_t *handle, const char *url, const char *localpath, - char **final_file, int force, int allow_resume, int errors_ok); +struct dload_payload { + char *filename; + char *fileurl; + long max_size; +}; + +void _alpm_dload_payload_free(struct dload_payload *payload); + +int _alpm_download(alpm_handle_t *handle, struct dload_payload *payload, + const char *localpath, char **final_file, int force, int allow_resume, + int errors_ok); #endif /* _ALPM_DLOAD_H */ -- cgit v1.2.3-24-g4f1b From 3eec745910bb908717a8b4ed7f5b630a92a5c9eb Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 30 Jun 2011 21:19:25 -0400 Subject: absorb some _alpm_download params into payload struct Restore some sanity to the number of arguments passed to _alpm_download and curl_download_internal. Signed-off-by: Dave Reisner --- lib/libalpm/dload.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/libalpm/dload.h') diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 6a2dd392..3945d245 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -34,16 +34,19 @@ struct fileinfo { }; struct dload_payload { + alpm_handle_t *handle; char *filename; char *fileurl; long max_size; + int force; + int allow_resume; + int errors_ok; }; void _alpm_dload_payload_free(struct dload_payload *payload); -int _alpm_download(alpm_handle_t *handle, struct dload_payload *payload, - const char *localpath, char **final_file, int force, int allow_resume, - int errors_ok); +int _alpm_download(struct dload_payload *payload, const char *localpath, + char **final_file); #endif /* _ALPM_DLOAD_H */ -- cgit v1.2.3-24-g4f1b From 57eac093c40b0a54ab5d9f14519b9e44140e0c3d Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 30 Jun 2011 22:00:07 -0400 Subject: absorb fileinfo struct into dload_payload This transitional struct becomes delicious noms for dload_payload. Signed-off-by: Dave Reisner --- lib/libalpm/dload.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lib/libalpm/dload.h') diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 3945d245..341a4a1a 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -25,18 +25,12 @@ #include -/* internal structure for communicating with curl progress callback */ -struct fileinfo { +struct dload_payload { alpm_handle_t *handle; const char *filename; char *cd_filename; - double initial_size; -}; - -struct dload_payload { - alpm_handle_t *handle; - char *filename; char *fileurl; + double initial_size; long max_size; int force; int allow_resume; -- cgit v1.2.3-24-g4f1b