From: Jo-Philipp Wich Date: Thu, 7 Dec 2017 10:43:02 +0000 (+0100) Subject: opkg: encode archive filenames while constructing download URLs X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9f003e32721cc74431e513804845c4e174e81d7f;p=oweals%2Fopkg-lede.git opkg: encode archive filenames while constructing download URLs 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 --- 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