[pacman-dev] [PATCH] Skip rename() on NULL destfile in curl_download_internal()
Lukas Fleischer
archlinux at cryptocrack.de
Wed Aug 17 10:45:35 EDT 2011
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 <archlinux at cryptocrack.de>
---
Untested, sorry. Should be trivial enough not to break anything though.
Hopefully.
lib/libalpm/dload.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 731d807..5cbb6b4 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -384,12 +384,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);
}
}
--
1.7.6
More information about the pacman-dev
mailing list