From 9cddc4ad80dbb52e30cdbcd168a4c19b73e30bbe Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 17 Aug 2011 16:45:35 +0200 Subject: Skip rename() on NULL destfile in curl_download_internal() Avoid a potential segfault that may occur if we use a temporary file and fail to build the destination file name from the effective URL. Signed-off-by: Lukas Fleischer Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 9f1285d0..fd5c9289 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -385,12 +385,16 @@ cleanup: } if(ret == 0) { - if(rename(tempfile, destfile)) { - _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"), - tempfile, destfile, strerror(errno)); - ret = -1; + if (destfile) { + if(rename(tempfile, destfile)) { + _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"), + tempfile, destfile, strerror(errno)); + ret = -1; + } else if(final_file) { + *final_file = strdup(strrchr(destfile, '/') + 1); + } } else if(final_file) { - *final_file = strdup(strrchr(destfile, '/') + 1); + *final_file = strdup(strrchr(tempfile, '/') + 1); } } -- cgit v1.2.3-24-g4f1b