From: Jordan Lee Date: Sun, 27 Apr 2014 20:17:16 +0000 (+0000) Subject: (trunk, libT) #5517 'Don't create or add torrents with "../" at the beginning of... X-Git-Tag: 2.83~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f5c7809e70798e71d7c6fa1ca4869d770bd34d4;p=transmission (trunk, libT) #5517 'Don't create or add torrents with "../" at the beginning of the path or "/../" anywhere in the path' -- fixed. --- diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 25f7ff91a..eb6ab0ac1 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -30,6 +30,19 @@ **** ***/ + +#ifdef WIN32 + #define PATH_DELIMITER_CHARS "/\\" +#else + #define PATH_DELIMITER_CHARS "/" +#endif + +static inline bool +char_is_path_separator (char c) +{ + return strchr(PATH_DELIMITER_CHARS, c) != NULL; +} + char* tr_metainfoGetBasename (const tr_info * inf) { @@ -39,7 +52,7 @@ tr_metainfoGetBasename (const tr_info * inf) char * ret = tr_strdup_printf ("%s.%16.16s", name, inf->hashString); for (i=0; iname)) + return "path"; + + buf = evbuffer_new (); + result = NULL; inf->isMultifile = 1; inf->fileCount = tr_variantListSize (files); @@ -129,27 +157,40 @@ parseFiles (tr_info * inf, tr_variant * files, const tr_variant * length) file = tr_variantListChild (files, i); if (!tr_variantIsDict (file)) - return "files"; + { + result = "files"; + break; + } if (!tr_variantDictFindList (file, TR_KEY_path_utf_8, &path)) if (!tr_variantDictFindList (file, TR_KEY_path, &path)) - return "path"; + { + result = "path"; + break; + } if (!getfile (&inf->files[i].name, inf->name, path, buf)) - return "path"; + { + result = "path"; + break; + } if (!tr_variantDictFindInt (file, TR_KEY_length, &len)) - return "length"; + { + result = "length"; + break; + } inf->files[i].length = len; inf->totalSize += len; } evbuffer_free (buf); + return result; } else if (tr_variantGetInt (length, &len)) /* single-file mode */ { - if (path_is_suspicious (inf->name)) + if (path_component_is_suspicious (inf->name)) return "path"; inf->isMultifile = 0;