aboutsummaryrefslogtreecommitdiff
path: root/system/curlftpfs
diff options
context:
space:
mode:
Diffstat (limited to 'system/curlftpfs')
-rw-r--r--system/curlftpfs/curlftpfs.SlackBuild32
-rw-r--r--system/curlftpfs/patches/curlftpfs-0.9.2-create-fix.patch33
-rw-r--r--system/curlftpfs/patches/curlftpfs-0.9.2-fix-escaping.patch420
-rw-r--r--system/curlftpfs/patches/curlftpfs-0.9.2-memleak-591298.patch15
-rw-r--r--system/curlftpfs/patches/curlftpfs-0.9.2-memleak-cached-591299.patch58
-rw-r--r--system/curlftpfs/patches/curlftpfs-0.9.2-offset_64_another.patch21
-rw-r--r--system/curlftpfs/patches/no-verify-hostname.patch14
7 files changed, 591 insertions, 2 deletions
diff --git a/system/curlftpfs/curlftpfs.SlackBuild b/system/curlftpfs/curlftpfs.SlackBuild
index a9bc8c18f48b4..8d3fd9e58e739 100644
--- a/system/curlftpfs/curlftpfs.SlackBuild
+++ b/system/curlftpfs/curlftpfs.SlackBuild
@@ -2,7 +2,7 @@
# Slackware build script for curlftpfs
-# Copyright 2008-2011 Heinz Wiesinger, Amsterdam, The Netherlands
+# Copyright 2008-2022 Heinz Wiesinger, Amsterdam, The Netherlands
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
@@ -29,7 +29,7 @@ cd $(dirname $0) ; CWD=$(pwd)
PRGNAM=curlftpfs
VERSION=${VERSION:-0.9.2}
-BUILD=${BUILD:-2}
+BUILD=${BUILD:-4}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}
@@ -79,6 +79,34 @@ find -L . \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \+
+# Apply patch from Gentoo
+
+# https://sourceforge.net/p/curlftpfs/bugs/65/
+# May also fix these:
+# https://sourceforge.net/p/curlftpfs/bugs/34/
+# https://sourceforge.net/p/curlftpfs/bugs/74/
+patch -p1 -i $CWD/patches/curlftpfs-0.9.2-fix-escaping.patch
+
+# Apply patches from Fedora
+
+# https://bugzilla.redhat.com/show_bug.cgi?id=962015
+patch -p1 -i $CWD/patches/curlftpfs-0.9.2-create-fix.patch
+
+# https://sourceforge.net/p/curlftpfs/bugs/52/
+patch -p1 -i $CWD/patches/curlftpfs-0.9.2-memleak-591298.patch
+
+# https://sourceforge.net/p/curlftpfs/bugs/58/
+patch -p1 -i $CWD/patches/curlftpfs-0.9.2-memleak-cached-591299.patch
+
+# https://sourceforge.net/p/curlftpfs/bugs/50/
+patch -p1 -i $CWD/patches/curlftpfs-0.9.2-offset_64_another.patch
+
+# Apply patch from Arch
+
+# https://bugs.archlinux.org/task/47906
+# https://sourceforge.net/p/curlftpfs/bugs/67/
+patch -p1 -i $CWD/patches/no-verify-hostname.patch
+
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
diff --git a/system/curlftpfs/patches/curlftpfs-0.9.2-create-fix.patch b/system/curlftpfs/patches/curlftpfs-0.9.2-create-fix.patch
new file mode 100644
index 0000000000000..4389d9d18ae8e
--- /dev/null
+++ b/system/curlftpfs/patches/curlftpfs-0.9.2-create-fix.patch
@@ -0,0 +1,33 @@
+diff -NaurEbBH -x '*.Plo' -x Makefile -x '*.log' -x '*.status' -x '*.list' -x '*.Po' -x libtool -x nbproject curlftpfs-0.9.2.orig/ftpfs.c curlftpfs-0.9.2/ftpfs.c
+--- curlftpfs-0.9.2.orig/ftpfs.c 2013-05-12 14:31:57.000000000 +0400
++++ curlftpfs-0.9.2/ftpfs.c 2013-05-12 14:29:00.906721322 +0400
+@@ -759,13 +759,13 @@
+ err = -ENOTSUP;
+ }
+
+- if ((fi->flags & O_EXCL))
+- {
+- DEBUG(1, "opening %s with O_EXCL - testing existence\n", path);
+- int exists_r = test_exists(path);
+- if (exists_r != -ENOENT)
+- err = -EACCES;
+- }
++// if ((fi->flags & O_EXCL))
++// {
++// DEBUG(1, "opening %s with O_EXCL - testing existence\n", path);
++// int exists_r = test_exists(path);
++// if (exists_r != -ENOENT)
++// err = -EACCES;
++// }
+
+ if (!err)
+ {
+@@ -816,6 +816,8 @@
+ #if FUSE_VERSION >= 25
+ static int ftpfs_create(const char* path, mode_t mode,
+ struct fuse_file_info* fi) {
++// return ftpfs_open_common(path, mode, fi);
++ ftpfs_mknod(path, mode, NULL);
+ return ftpfs_open_common(path, mode, fi);
+ }
+ #endif
diff --git a/system/curlftpfs/patches/curlftpfs-0.9.2-fix-escaping.patch b/system/curlftpfs/patches/curlftpfs-0.9.2-fix-escaping.patch
new file mode 100644
index 0000000000000..df15bddd562f6
--- /dev/null
+++ b/system/curlftpfs/patches/curlftpfs-0.9.2-fix-escaping.patch
@@ -0,0 +1,420 @@
+fix handling of special symbols in file operations.
+
+Path fixes at least following cases:
+ - attempt to enter directory named '#'
+ - attempt to open file named '#'
+ - attempt to dereference link named '#'
+ - attempt to chown file / dir named '#'
+
+The fix is basically following mechanical conversion:
+--- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, something);
++++ something_uri = path_to_uri(something);
++++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, something_uri);
+=== curl_easy_perform();
++++ free_uri(something_uri);
+
+What is not yet converted is ftp hostname.
+
+Reported-by: Jaakko Perttilä
+Gentoo-bug: http://bugs.gentoo.org/458110
+Based-on-patch: https://github.com/jomat/curlftpfs/commit/da20298fd0d0dcefc7d6d69ffecbc5544e783cfe
+Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+diff --git a/ftpfs.c b/ftpfs.c
+index ffd0b28..f21a267 100644
+--- a/ftpfs.c
++++ b/ftpfs.c
+@@ -257,6 +257,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h,
+ int err = 0;
+ CURLcode curl_res;
+ char* dir_path = get_fulldir_path(path);
++ char* dir_path_uri = path_to_uri(dir_path);
+
+ DEBUG(1, "ftpfs_getdir: %s\n", dir_path);
+ struct buffer buf;
+@@ -264,7 +265,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h,
+
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_res = curl_easy_perform(ftpfs.connection);
+ pthread_mutex_unlock(&ftpfs.lock);
+@@ -278,6 +279,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_dirh_t h,
+ NULL, NULL, NULL, 0, h, filler);
+ }
+
++ free_uri(dir_path_uri);
+ free(dir_path);
+ buf_free(&buf);
+ return op_return(err, "ftpfs_getdir");
+@@ -287,6 +289,7 @@ static int ftpfs_getattr(const char* path, struct stat* sbuf) {
+ int err;
+ CURLcode curl_res;
+ char* dir_path = get_dir_path(path);
++ char* dir_path_uri = path_to_uri(dir_path);
+
+ DEBUG(2, "ftpfs_getattr: %s dir_path=%s\n", path, dir_path);
+ struct buffer buf;
+@@ -294,7 +297,7 @@ static int ftpfs_getattr(const char* path, struct stat* sbuf) {
+
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_res = curl_easy_perform(ftpfs.connection);
+ pthread_mutex_unlock(&ftpfs.lock);
+@@ -309,6 +312,7 @@ static int ftpfs_getattr(const char* path, struct stat* sbuf) {
+ err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,
+ name, sbuf, NULL, 0, NULL, NULL);
+
++ free_uri(dir_path_uri);
+ free(dir_path);
+ buf_free(&buf);
+ if (err) return op_return(-ENOENT, "ftpfs_getattr");
+@@ -329,6 +333,7 @@ static size_t ftpfs_read_chunk(const char* full_path, char* rbuf,
+ int running_handles = 0;
+ int err = 0;
+ struct ftpfs_file* fh = get_ftpfs_file(fi);
++ char* full_path_uri = path_to_uri(full_path); /* TODO: optimize bu pushing up conversion to context */
+
+ DEBUG(2, "ftpfs_read_chunk: %s %p %zu %lld %p %p\n",
+ full_path, rbuf, size, offset, fi, fh);
+@@ -355,7 +360,7 @@ static size_t ftpfs_read_chunk(const char* full_path, char* rbuf,
+
+ cancel_previous_multi();
+
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);
+ if (offset) {
+ char range[15];
+@@ -444,6 +449,7 @@ static size_t ftpfs_read_chunk(const char* full_path, char* rbuf,
+
+ pthread_mutex_unlock(&ftpfs.lock);
+
++ free_uri(full_path_uri);
+ if (err) return CURLFTPFS_BAD_READ;
+ return size;
+ }
+@@ -497,11 +503,12 @@ int write_thread_ctr = 0;
+ static void *ftpfs_write_thread(void *data) {
+ struct ftpfs_file *fh = data;
+ char range[15];
+-
++ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */
++
+ DEBUG(2, "enter streaming write thread #%d path=%s pos=%lld\n", ++write_thread_ctr, fh->full_path, fh->pos);
+
+
+- curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, fh->full_path);
++ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_UPLOAD, 1);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_INFILESIZE, (curl_off_t)-1);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_READFUNCTION, write_data_bg);
+@@ -541,6 +548,8 @@ static void *ftpfs_write_thread(void *data) {
+
+ sem_post(&fh->data_written); /* ftpfs_write may return */
+
++ free_uri(full_path_uri);
++
+ return NULL;
+ }
+
+@@ -621,16 +630,19 @@ static void free_ftpfs_file(struct ftpfs_file *fh) {
+ }
+
+ static int buffer_file(struct ftpfs_file *fh) {
++ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */
+ // If we want to write to the file, we have to load it all at once,
+ // modify it in memory and then upload it as a whole as most FTP servers
+ // don't support resume for uploads.
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, fh->full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+ pthread_mutex_unlock(&ftpfs.lock);
+
++ free_uri(full_path_uri);
++
+ if (curl_res != 0) {
+ return -EACCES;
+ }
+@@ -643,10 +655,11 @@ static int create_empty_file(const char * path)
+ int err = 0;
+
+ char *full_path = get_full_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_INFILESIZE, 0);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_UPLOAD, 1);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_READDATA, NULL);
+@@ -656,7 +669,9 @@ static int create_empty_file(const char * path)
+
+ if (curl_res != 0) {
+ err = -EPERM;
+- }
++ }
++
++ free_uri(full_path_uri);
+ free(full_path);
+ return err;
+ }
+@@ -875,6 +890,7 @@ static int ftpfs_chmod(const char* path, mode_t mode) {
+
+ struct curl_slist* header = NULL;
+ char* full_path = get_dir_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+ char* filename = get_file_name(path);
+ char* cmd = g_strdup_printf("SITE CHMOD %.3o %s", mode_c, filename);
+ struct buffer buf;
+@@ -885,7 +901,7 @@ static int ftpfs_chmod(const char* path, mode_t mode) {
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+@@ -896,12 +912,13 @@ static int ftpfs_chmod(const char* path, mode_t mode) {
+ if (curl_res != 0) {
+ err = -EPERM;
+ }
+-
++
+ buf_free(&buf);
+ curl_slist_free_all(header);
++ free_uri(full_path_uri);
+ free(full_path);
+ free(filename);
+- free(cmd);
++ free(cmd);
+ return op_return(err, "ftpfs_chmod");
+ }
+
+@@ -912,6 +929,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gid_t gid) {
+
+ struct curl_slist* header = NULL;
+ char* full_path = get_dir_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+ char* filename = get_file_name(path);
+ char* cmd = g_strdup_printf("SITE CHUID %i %s", uid, filename);
+ char* cmd2 = g_strdup_printf("SITE CHGID %i %s", gid, filename);
+@@ -924,7 +942,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gid_t gid) {
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+@@ -938,6 +956,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gid_t gid) {
+
+ buf_free(&buf);
+ curl_slist_free_all(header);
++ free_uri(full_path_uri);
+ free(full_path);
+ free(filename);
+ free(cmd);
+@@ -1001,6 +1020,7 @@ static int ftpfs_rmdir(const char* path) {
+ int err = 0;
+ struct curl_slist* header = NULL;
+ char* full_path = get_dir_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+ char* filename = get_file_name(path);
+ char* cmd = g_strdup_printf("RMD %s", filename);
+ struct buffer buf;
+@@ -1014,7 +1034,7 @@ static int ftpfs_rmdir(const char* path) {
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+@@ -1028,6 +1048,7 @@ static int ftpfs_rmdir(const char* path) {
+
+ buf_free(&buf);
+ curl_slist_free_all(header);
++ free_uri(full_path_uri);
+ free(full_path);
+ free(filename);
+ free(cmd);
+@@ -1038,6 +1059,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode) {
+ int err = 0;
+ struct curl_slist* header = NULL;
+ char* full_path = get_dir_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+ char* filename = get_file_name(path);
+ char* cmd = g_strdup_printf("MKD %s", filename);
+ struct buffer buf;
+@@ -1048,7 +1070,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode) {
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+@@ -1062,6 +1084,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode) {
+
+ buf_free(&buf);
+ curl_slist_free_all(header);
++ free_uri(full_path_uri);
+ free(full_path);
+ free(filename);
+ free(cmd);
+@@ -1076,6 +1099,7 @@ static int ftpfs_unlink(const char* path) {
+ int err = 0;
+ struct curl_slist* header = NULL;
+ char* full_path = get_dir_path(path);
++ char* full_path_uri = path_to_uri(full_path);
+ char* filename = get_file_name(path);
+ char* cmd = g_strdup_printf("DELE %s", filename);
+ struct buffer buf;
+@@ -1086,7 +1110,7 @@ static int ftpfs_unlink(const char* path) {
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
+@@ -1100,6 +1124,7 @@ static int ftpfs_unlink(const char* path) {
+
+ buf_free(&buf);
+ curl_slist_free_all(header);
++ free_uri(full_path_uri);
+ free(full_path);
+ free(filename);
+ free(cmd);
+@@ -1301,6 +1326,7 @@ static int ftpfs_readlink(const char *path, char *linkbuf, size_t size) {
+ int err;
+ CURLcode curl_res;
+ char* dir_path = get_dir_path(path);
++ char* dir_path_uri = path_to_uri(dir_path);
+
+ DEBUG(2, "dir_path: %s %s\n", path, dir_path);
+ struct buffer buf;
+@@ -1308,7 +1334,7 @@ static int ftpfs_readlink(const char *path, char *linkbuf, size_t size) {
+
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
++ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
+ curl_res = curl_easy_perform(ftpfs.connection);
+ pthread_mutex_unlock(&ftpfs.lock);
+@@ -1323,6 +1349,7 @@ static int ftpfs_readlink(const char *path, char *linkbuf, size_t size) {
+ err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,
+ name, NULL, linkbuf, size, NULL, NULL);
+
++ free_uri(dir_path_uri);
+ free(dir_path);
+ buf_free(&buf);
+ if (err) return op_return(-ENOENT, "ftpfs_readlink");
+diff --git a/path_utils.c b/path_utils.c
+index db3d7e4..214b5e6 100644
+--- a/path_utils.c
++++ b/path_utils.c
+@@ -92,3 +92,72 @@ char* get_dir_path(const char* path) {
+
+ return ret;
+ }
++
++/*
++ * the chars not needed to be escaped:
++ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
++ */
++static inline int is_unreserved_rfc3986(char c)
++{
++ int is_locase_alpha = (c >= 'a' && c <= 'z');
++ int is_upcase_alpha = (c >= 'a' && c <= 'z');
++ int is_digit = (c >= '0' && c <= '9');
++ int is_special = c == '-'
++ || c == '.'
++ || c == '_'
++ || c == '~';
++ int is_unreserved = is_locase_alpha
++ || is_upcase_alpha
++ || is_digit
++ || is_special;
++
++ return is_unreserved;
++}
++
++static inline int is_unreserved(char c)
++{
++ return is_unreserved_rfc3986(c) || c == '/';
++}
++
++char* path_to_uri(const char* path)
++{
++ static const char hex[] = "0123456789ABCDEF";
++ size_t path_len = strlen(path);
++ size_t host_len = strlen(ftpfs.host);
++ /* at worst: c -> %XX */
++ char * encoded_path = malloc (3 * path_len + 1);
++ const char * s = path;
++ char * d = encoded_path;
++
++ /*
++ * 'path' is always prefixed with 'ftpfs.host'
++ */
++ memcpy (d, ftpfs.host, host_len);
++ s += host_len;
++ d += host_len;
++
++ for (; *s; ++s)
++ {
++ char c = *s;
++ if (is_unreserved (c))
++ {
++ *d++ = c;
++ }
++ else
++ {
++ unsigned int hi = ((unsigned)c >> 4) & 0xF;
++ unsigned int lo = ((unsigned)c >> 0) & 0xF;
++ *d++ = '%';
++ *d++ = hex[hi];
++ *d++ = hex[lo];
++ }
++ }
++ *d = '\0';
++
++ return encoded_path;
++}
++
++void free_uri(char* path)
++{
++ free(path);
++}
+diff --git a/path_utils.h b/path_utils.h
+index 084ae4d..e3e9bca 100644
+--- a/path_utils.h
++++ b/path_utils.h
+@@ -6,4 +6,11 @@ char* get_full_path(const char* path);
+ char* get_fulldir_path(const char* path);
+ char* get_dir_path(const char* path);
+
++/*
++ * Transforms UNIX path to RFC3986 encoded path
++ * (CURLOPT_URL accepts only such paths)
++ */
++char* path_to_uri(const char* path);
++void free_uri(char* path);
++
+ #endif /* __CURLFTPFS_PATH_UTILS_H__ */
diff --git a/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-591298.patch b/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-591298.patch
new file mode 100644
index 0000000000000..94f46ba5c3607
--- /dev/null
+++ b/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-591298.patch
@@ -0,0 +1,15 @@
+@@ -, +, @@
+---
+ ftpfs.c | 2 2 + 0 - 0 !
+ 1 file changed, 2 insertions(+)
+--- b/ftpfs.c
++++ b/ftpfs.c
+@@ -615,6 +615,8 @@ static void free_ftpfs_file(struct ftpfs
+ sem_destroy(&fh->data_need);
+ sem_destroy(&fh->data_written);
+ sem_destroy(&fh->ready);
++ if (fh->buf.size) { buf_free(&fh->buf); }
++ if (fh->stream_buf.size) { buf_free(&fh->stream_buf); }
+ free(fh);
+ }
+
diff --git a/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-cached-591299.patch b/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-cached-591299.patch
new file mode 100644
index 0000000000000..d08c1f82d4972
--- /dev/null
+++ b/system/curlftpfs/patches/curlftpfs-0.9.2-memleak-cached-591299.patch
@@ -0,0 +1,58 @@
+@@ -, +, @@
+---
+ cache.c | 2 1 + 1 - 0 !
+ ftpfs-ls.c | 19 15 + 4 - 0 !
+ 2 files changed, 16 insertions(+), 5 deletions(-)
+--- b/cache.c
++++ b/cache.c
+@@ -25,7 +25,7 @@ struct cache {
+ time_t last_cleaned;
+ };
+
+-static struct cache cache;
++struct cache cache;
+
+ struct node {
+ struct stat stat;
+--- b/ftpfs-ls.c
++++ b/ftpfs-ls.c
+@@ -25,6 +25,13 @@
+ #include "charset_utils.h"
+ #include "ftpfs-ls.h"
+
++struct cache {
++ int on;
++ char incomplete[];
++};
++
++extern struct cache cache;
++
+ static int parse_dir_unix(const char *line,
+ struct stat *sbuf,
+ char *file,
+@@ -243,8 +250,10 @@ int parse_dir(const char* list, const ch
+ reallink = g_strdup(link);
+ }
+ int linksize = strlen(reallink);
+- cache_add_link(full_path, reallink, linksize+1);
+- DEBUG(1, "cache_add_link: %s %s\n", full_path, reallink);
++ if (cache.on) {
++ cache_add_link(full_path, reallink, linksize+1);
++ DEBUG(1, "cache_add_link: %s %s\n", full_path, reallink);
++ }
+ if (linkbuf && linklen) {
+ if (linksize > linklen) linksize = linklen - 1;
+ strncpy(linkbuf, reallink, linksize);
+@@ -257,8 +266,10 @@ int parse_dir(const char* list, const ch
+ DEBUG(1, "filler: %s\n", file);
+ filler(h, file, &stat_buf);
+ } else {
+- DEBUG(1, "cache_add_attr: %s\n", full_path);
+- cache_add_attr(full_path, &stat_buf);
++ if (cache.on) {
++ DEBUG(1, "cache_add_attr: %s\n", full_path);
++ cache_add_attr(full_path, &stat_buf);
++ }
+ }
+
+ DEBUG(2, "comparing %s %s\n", name, file);
diff --git a/system/curlftpfs/patches/curlftpfs-0.9.2-offset_64_another.patch b/system/curlftpfs/patches/curlftpfs-0.9.2-offset_64_another.patch
new file mode 100644
index 0000000000000..f3d85df32b58a
--- /dev/null
+++ b/system/curlftpfs/patches/curlftpfs-0.9.2-offset_64_another.patch
@@ -0,0 +1,21 @@
+@@ -, +, @@
+ ftpfs.c | 4 2 + 2 - 0 !
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+--- b/ftpfs.c
++++ b/ftpfs.c
+@@ -503,7 +503,6 @@ static void *ftpfs_write_thread(void *da
+
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, full_path_uri);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_UPLOAD, 1);
+- curl_easy_setopt_or_die(fh->write_conn, CURLOPT_INFILESIZE, -1);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_READFUNCTION, write_data_bg);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_READDATA, fh);
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_LOW_SPEED_LIMIT, 1);
+@@ -645,7 +645,6 @@ static int create_empty_file(const char
+ pthread_mutex_lock(&ftpfs.lock);
+ cancel_previous_multi();
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
+- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_INFILESIZE, 0);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_UPLOAD, 1);
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_READDATA, NULL);
+ CURLcode curl_res = curl_easy_perform(ftpfs.connection);
diff --git a/system/curlftpfs/patches/no-verify-hostname.patch b/system/curlftpfs/patches/no-verify-hostname.patch
new file mode 100644
index 0000000000000..cf0d410ad924d
--- /dev/null
+++ b/system/curlftpfs/patches/no-verify-hostname.patch
@@ -0,0 +1,14 @@
+diff -aur curlftpfs-0.9.2.orig/ftpfs.c curlftpfs-0.9.2.new/ftpfs.c
+--- curlftpfs-0.9.2.orig/ftpfs.c 2016-01-25 17:01:32.150581272 +0100
++++ curlftpfs-0.9.2.new/ftpfs.c 2016-01-25 17:02:08.566538053 +0100
+@@ -1625,9 +1625,7 @@
+ }
+
+ if (ftpfs.no_verify_hostname) {
+- /* The default is 2 which verifies even the host string. This sets to 1
+- * which means verify the host but not the string. */
+- curl_easy_setopt_or_die(easy, CURLOPT_SSL_VERIFYHOST, 1);
++ curl_easy_setopt_or_die(easy, CURLOPT_SSL_VERIFYHOST, 0);
+ }
+
+ curl_easy_setopt_or_die(easy, CURLOPT_INTERFACE, ftpfs.interface);