From 9f003e32721cc74431e513804845c4e174e81d7f Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 7 Dec 2017 11:43:02 +0100 Subject: [PATCH] opkg: encode archive filenames while constructing download URLs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Various web servers, namely Amazon S3 ones, have problems handling requests to URLs with a literal "+" in the path component. According to the RFC 3986 "+" is a reserved char and its purpose is delimiting. When used in a file name it should be encoded. Use the new urlencode_path() helper to encode the path component before constructing the final download URL. Signed-off-by: Jo-Philipp Wich Tested-by: Rafał Miłecki --- libopkg/opkg.c | 7 ++++--- libopkg/opkg_download.c | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libopkg/opkg.c b/libopkg/opkg.c index d994bd1..aba6364 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -260,7 +260,7 @@ opkg_install_package(const char *package_name, /* download package and dependencies */ for (i = 0; i < deps->len; i++) { pkg_t *pkg; - char *url; + char *url, *urlencoded_path; pkg = deps->pkgs[i]; if (pkg_get_string(pkg, PKG_LOCAL_FILENAME)) @@ -276,8 +276,9 @@ opkg_install_package(const char *package_name, } filename = pkg_get_string(pkg, PKG_FILENAME); - - sprintf_alloc(&url, "%s/%s", pkg->src->value, filename); + urlencoded_path = urlencode_path(filename); + sprintf_alloc(&url, "%s/%s", pkg->src->value, urlencoded_path); + free(urlencoded_path); /* Get the filename part, without any directory */ stripped_filename = strrchr(filename, '/'); diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index 36db231..e57d053 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -186,6 +186,7 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir) char *url; char *local_filename; char *stripped_filename; + char *urlencoded_path; char *filename; if (pkg->src == NULL) { @@ -204,7 +205,9 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir) return -1; } - sprintf_alloc(&url, "%s/%s", pkg->src->value, filename); + urlencoded_path = urlencode_path(filename); + sprintf_alloc(&url, "%s/%s", pkg->src->value, urlencoded_path); + free(urlencoded_path); /* The filename might be something like "../../foo.opk". While this is correct, and exactly what we -- 2.30.2