From f4875fab9bbe3011446032bebcbe232448a3e8d7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 17 Oct 2011 09:47:06 -0400 Subject: dload: chmod tempfiles to respect umask Dan: fix mask calculation, add it to the success/fail block instead. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 9d919b0a..546329b3 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -178,6 +178,14 @@ static int utimes_long(const char *path, long seconds) return 0; } +/* prefix to avoid possible future clash with getumask(3) */ +static mode_t _getumask(void) +{ + mode_t mask = umask(0); + umask(mask); + return mask; +} + static size_t parse_headers(void *ptr, size_t size, size_t nmemb, void *user) { size_t realsize = size * nmemb; @@ -295,9 +303,12 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat MALLOC(randpath, len, RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL)); snprintf(randpath, len, "%salpmtmp.XXXXXX", localpath); if((fd = mkstemp(randpath)) == -1 || + fchmod(fd, ~(_getumask()) & 0666) || !(fp = fdopen(fd, payload->tempfile_openmode))) { unlink(randpath); - close(fd); + if(fd >= 0) { + close(fd); + } _alpm_log(payload->handle, ALPM_LOG_ERROR, _("failed to create temporary file for download\n")); return NULL; -- cgit v1.2.3-24-g4f1b From 4c259d51f7e0d5fac0158f70b0ad3b0043930943 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 22 Oct 2011 13:16:39 -0400 Subject: dload: remove redundant conditional Replacing the strdup when after the first NULL check assures that we get continue with payload->remote_name defined. Signed-off-by: Dave Reisner --- lib/libalpm/dload.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 546329b3..efd469d5 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -345,9 +345,10 @@ static int curl_download_internal(struct dload_payload *payload, payload->tempfile_openmode = "wb"; if(!payload->remote_name) { - payload->remote_name = strdup(get_filename(payload->fileurl)); + STRDUP(payload->remote_name, get_filename(payload->fileurl), + RET_ERR(handle, ALPM_ERR_MEMORY, -1)); } - if(!payload->remote_name || curl_gethost(payload->fileurl, hostname, sizeof(hostname)) != 0) { + if(curl_gethost(payload->fileurl, hostname, sizeof(hostname)) != 0) { _alpm_log(handle, ALPM_LOG_ERROR, _("url '%s' is invalid\n"), payload->fileurl); RET_ERR(handle, ALPM_ERR_SERVER_BAD_URL, -1); } -- cgit v1.2.3-24-g4f1b