Bug 1637745. r=Gijs,necko-reviewers,mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D80345
This commit is contained in:
Marco Bonardo 2020-07-17 13:45:58 +00:00
Родитель f07c0832e3
Коммит 9717edb569
5 изменённых файлов: 22 добавлений и 0 удалений

Просмотреть файл

@ -605,6 +605,8 @@ void nsDocShellLoadState::SetTypeHint(const nsCString& aTypeHint) {
const nsString& nsDocShellLoadState::FileName() const { return mFileName; }
void nsDocShellLoadState::SetFileName(const nsAString& aFileName) {
MOZ_DIAGNOSTIC_ASSERT(aFileName.FindChar(char16_t(0)) == kNotFound,
"The filename should never contain null characters");
mFileName = aFileName;
}

Просмотреть файл

@ -5258,6 +5258,11 @@ void nsContentUtils::TriggerLink(nsIContent* aContent, nsIURI* aLinkURI,
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aContent->NodePrincipal();
nsCOMPtr<nsIContentSecurityPolicy> csp = aContent->GetCsp();
// Sanitize fileNames containing null characters by replacing them with
// underscores.
if (!fileName.IsVoid()) {
fileName.ReplaceChar(char16_t(0), '_');
}
nsDocShell::Cast(docShell)->OnLinkClick(
aContent, aLinkURI, fileName.IsVoid() ? aTargetSpec : EmptyString(),
fileName, nullptr, nullptr, UserActivation::IsHandlingUserInput(),

Просмотреть файл

@ -604,6 +604,12 @@ nsBaseChannel::SetContentDispositionFilename(
const nsAString& aContentDispositionFilename) {
mContentDispositionFilename =
MakeUnique<nsString>(aContentDispositionFilename);
// For safety reasons ensure the filename doesn't contain null characters and
// replace them with underscores. We may later pass the extension to system
// MIME APIs that expect null terminated strings.
mContentDispositionFilename->ReplaceChar(char16_t(0), '_');
return NS_OK;
}

Просмотреть файл

@ -701,6 +701,12 @@ HttpBaseChannel::SetContentDispositionFilename(
const nsAString& aContentDispositionFilename) {
mContentDispositionFilename =
MakeUnique<nsString>(aContentDispositionFilename);
// For safety reasons ensure the filename doesn't contain null characters and
// replace them with underscores. We may later pass the extension to system
// MIME APIs that expect null terminated strings.
mContentDispositionFilename->ReplaceChar(char16_t(0), '_');
return NS_OK;
}

Просмотреть файл

@ -1230,6 +1230,7 @@ nsExternalAppHandler::nsExternalAppHandler(
// code sanitization in DownloadPaths.jsm
mSuggestedFileName.ReplaceChar(KNOWN_PATH_SEPARATORS, '_');
mSuggestedFileName.ReplaceChar(FILE_ILLEGAL_CHARACTERS, ' ');
mSuggestedFileName.ReplaceChar(char16_t(0), '_');
mTempFileExtension.ReplaceChar(KNOWN_PATH_SEPARATORS, '_');
mTempFileExtension.ReplaceChar(FILE_ILLEGAL_CHARACTERS, ' ');
@ -2520,6 +2521,8 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(
nsIMIMEInfo** _retval) {
MOZ_ASSERT(!aMIMEType.IsEmpty() || !aFileExt.IsEmpty(),
"Give me something to work with");
MOZ_DIAGNOSTIC_ASSERT(aFileExt.FindChar('\0') == kNotFound,
"The extension should never contain null characters");
LOG(("Getting mimeinfo from type '%s' ext '%s'\n",
PromiseFlatCString(aMIMEType).get(),
PromiseFlatCString(aFileExt).get()));