[pacman-dev] Check that destfile_name exists before using it

Message ID 20200713163534.58537-1-anatol.pomozov@gmail.com
State Accepted, archived
Headers show
Series [pacman-dev] Check that destfile_name exists before using it | expand

Commit Message

Anatol Pomozov July 13, 2020, 4:35 p.m. UTC
In some cases (when trust_remote_name is used for a URL without a filename and
no Content-Disposition is provided by the server) destfile_name will be
NULL. In this case payload data will be stored in tempfile_name and no
destfile_name is set.

Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
---
 lib/libalpm/dload.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Anatol Pomozov July 13, 2020, 4:37 p.m. UTC | #1
Hi

This and the "Build signature remote name based" patches are needed to
fix corner cases discovered by Andrew's test cases.
Allan McRae July 14, 2020, 1:43 p.m. UTC | #2
On 14/7/20 2:35 am, Anatol Pomozov wrote:
> In some cases (when trust_remote_name is used for a URL without a filename and
> no Content-Disposition is provided by the server) destfile_name will be
> NULL. In this case payload data will be stored in tempfile_name and no
> destfile_name is set.
> 
> Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
> ---

Thanks.

A

Patch

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 343f5c78..673e769f 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -897,15 +897,18 @@  int SYMEXPORT alpm_fetch_pkgurl(alpm_handle_t *handle, const alpm_list_t *urls,
 
 		for(i = payloads; i; i = i->next) {
 			struct dload_payload *payload = i->data;
-			const char *filename;
 			char *filepath;
 
 			if(payload->signature) {
 				continue;
 			}
 
-			filename = mbasename(payload->destfile_name);
-			filepath = _alpm_filecache_find(handle, filename);
+			if(payload->destfile_name) {
+				const char *filename = mbasename(payload->destfile_name);
+				filepath = _alpm_filecache_find(handle, filename);
+			} else {
+				STRDUP(filepath, payload->tempfile_name, GOTO_ERR(handle, ALPM_ERR_MEMORY, err));
+			}
 			if(filepath) {
 				alpm_list_append(fetched, filepath);
 			} else {