diff --git a/mozilla/xpcom/io/nsILocalFile.idl b/mozilla/xpcom/io/nsILocalFile.idl index 75eef1442d7..c0dc6026d71 100644 --- a/mozilla/xpcom/io/nsILocalFile.idl +++ b/mozilla/xpcom/io/nsILocalFile.idl @@ -64,6 +64,18 @@ interface nsILocalFile : nsIFile [noscript] PRLibraryStar load(); readonly attribute PRInt64 diskSpaceAvailable; // maybe we should put this somewhere else. + + /** + * appendRelativePath + * + * Append a relative path to the current path of the nsILocalFile object. + * + * @param relativeFilePath + * relativeFilePath is a native relative path. For security reasons, + * this cannot contain .. or cannot start with a directory separator + */ + void appendRelativePath([const] in string relativeFilePath); + void appendRelativeUnicodePath([const] in wstring relativeFilePath); }; %{C++ diff --git a/mozilla/xpcom/io/nsLocalFileCommon.cpp b/mozilla/xpcom/io/nsLocalFileCommon.cpp index a63c0bcd77e..e65c779af38 100644 --- a/mozilla/xpcom/io/nsLocalFileCommon.cpp +++ b/mozilla/xpcom/io/nsLocalFileCommon.cpp @@ -240,6 +240,11 @@ nsLocalFile::AppendUnicode(const PRUnichar *node) SET_UCS( Append , node); } NS_IMETHODIMP +nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) +{ + SET_UCS( AppendRelativePath , node); +} +NS_IMETHODIMP nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) { GET_UCS(GetLeafName, aLeafName); diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index a0f92cc7276..aba6cd700ba 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -1119,9 +1119,18 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) return NS_ERROR_FILE_UNKNOWN_TYPE; } - + NS_IMETHODIMP nsLocalFile::Append(const char *node) +{ + if (!node || (strstr(node, ":") != nsnull)) + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + + return AppendRelativePath(node); +} + +NS_IMETHODIMP +nsLocalFile::AppendRelativePath(const char *node) { if ( (node == nsnull) ) return NS_ERROR_FILE_UNRECOGNIZED_PATH; diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 5df926d029c..c4512e8e3df 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -417,6 +417,28 @@ nsLocalFile::Append(const char *fragment) { NS_ENSURE_ARG(fragment); CHECK_mPath(); + + // only one component of path can be appended + if (strstr(fragment, "/") != nsnull) + { + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + } + + return AppendRelativePath(fragment); +} + +NS_IMETHODIMP +nsLocalFile::AppendRelativePath(const char *fragment) +{ + NS_ENSURE_ARG(fragment); + CHECK_mPath(); + + // Cannot start with a '/' and no .. allowed in the fragment + if ((*fragment == '/') || (strstr(fragment, "..") != nsnull)) + { + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + } + char * newPath = (char *)nsAllocator::Alloc(strlen(mPath) + strlen(fragment) + 2); if (!newPath) diff --git a/mozilla/xpcom/io/nsLocalFileWin.cpp b/mozilla/xpcom/io/nsLocalFileWin.cpp index a7a9e526119..38460e6a644 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.cpp +++ b/mozilla/xpcom/io/nsLocalFileWin.cpp @@ -694,11 +694,20 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) NS_IMETHODIMP nsLocalFile::Append(const char *node) { - if ( (node == nsnull) || - (*node == '/') || - (strstr(node, "..") != nsnull) || - (_mbschr((const unsigned char*) node, '\\') != nsnull) || - (strchr(node, '/') != nsnull) ) + // Append only one component. Check for subdirs. + if (!node || (_mbschr((const unsigned char*) node, '\\') != nsnull)) + { + return NS_ERROR_FILE_UNRECOGNIZED_PATH; + } + return AppendRelativePath(node); +} + +NS_IMETHODIMP +nsLocalFile::AppendRelativePath(const char *node) +{ + // Cannot start with a / or have .. or have / anywhere + if (!node || (*node == '/') || (strstr(node, "..") != nsnull) || + (strchr(node, '/') != nsnull)) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; }