mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backing out part of bug 369428 that seems to be causing unit test failures
This commit is contained in:
parent
2bf5706a7b
commit
1b0518d3eb
@ -120,10 +120,6 @@
|
|||||||
|
|
||||||
#include "nsLocalHandlerApp.h"
|
#include "nsLocalHandlerApp.h"
|
||||||
|
|
||||||
#include "nsIRandomGenerator.h"
|
|
||||||
#include "plbase64.h"
|
|
||||||
#include "prmem.h"
|
|
||||||
|
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
PRLogModuleInfo* nsExternalHelperAppService::mLog = nsnull;
|
PRLogModuleInfo* nsExternalHelperAppService::mLog = nsnull;
|
||||||
#endif
|
#endif
|
||||||
@ -1077,6 +1073,14 @@ void nsExternalAppHandler::RetargetLoadNotifications(nsIRequest *request)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SALT_SIZE 8
|
||||||
|
#define TABLE_SIZE 36
|
||||||
|
const PRUnichar table[] =
|
||||||
|
{ 'a','b','c','d','e','f','g','h','i','j',
|
||||||
|
'k','l','m','n','o','p','q','r','s','t',
|
||||||
|
'u','v','w','x','y','z','0','1','2','3',
|
||||||
|
'4','5','6','7','8','9'};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make mTempFileExtension contain an extension exactly when its previous value
|
* Make mTempFileExtension contain an extension exactly when its previous value
|
||||||
* is different from mSuggestedFileName's extension, so that it can be appended
|
* is different from mSuggestedFileName's extension, so that it can be appended
|
||||||
@ -1128,56 +1132,36 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel)
|
|||||||
#endif
|
#endif
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// At this point, we do not have a filename for the temp file. For security
|
// We need to generate a name for the temp file that we are going to be streaming data to.
|
||||||
// purposes, this cannot be predictable, so we must use a cryptographic
|
// We don't want this name to be predictable for security reasons so we are going to generate a
|
||||||
// quality PRNG to generate one.
|
// "salted" name.....
|
||||||
// We will request raw random bytes, and transform that to a base64 string,
|
nsAutoString saltedTempLeafName;
|
||||||
// as all characters from the base64 set are acceptable for filenames. For
|
// this salting code was ripped directly from the profile manager.
|
||||||
// each three bytes of random data, we will get four bytes of ASCII. Request
|
// turn PR_Now() into milliseconds since epoch
|
||||||
// a bit more, to be safe, and truncate to the length we want in the end.
|
// and salt rand with that.
|
||||||
|
double fpTime;
|
||||||
const PRUint32 wantedFileNameLength = 8;
|
LL_L2D(fpTime, PR_Now());
|
||||||
const PRUint32 requiredBytesLength =
|
srand((uint)(fpTime * 1e-6 + 0.5));
|
||||||
static_cast<PRUint32>((wantedFileNameLength + 1) / 4 * 3);
|
PRInt32 i;
|
||||||
|
for (i=0;i<SALT_SIZE;i++)
|
||||||
nsCOMPtr<nsIRandomGenerator> rg =
|
{
|
||||||
do_GetService("@mozilla.org/security/random-generator;1", &rv);
|
saltedTempLeafName.Append(table[(rand()%TABLE_SIZE)]);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
}
|
||||||
|
|
||||||
PRUint8 *buffer;
|
|
||||||
rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
char *b64 = PL_Base64Encode(reinterpret_cast<const char *>(buffer),
|
|
||||||
requiredBytesLength, nsnull);
|
|
||||||
NS_Free(buffer);
|
|
||||||
buffer = nsnull;
|
|
||||||
|
|
||||||
if (!b64)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
NS_ASSERTION(strlen(b64) >= wantedFileNameLength,
|
|
||||||
"not enough bytes produced for conversion!");
|
|
||||||
|
|
||||||
nsCAutoString tempLeafName(b64, wantedFileNameLength);
|
|
||||||
PR_Free(b64);
|
|
||||||
b64 = nsnull;
|
|
||||||
|
|
||||||
// now append our extension.
|
// now append our extension.
|
||||||
nsCAutoString ext;
|
nsCAutoString ext;
|
||||||
mMimeInfo->GetPrimaryExtension(ext);
|
mMimeInfo->GetPrimaryExtension(ext);
|
||||||
if (!ext.IsEmpty()) {
|
if (!ext.IsEmpty()) {
|
||||||
if (ext.First() != '.')
|
if (ext.First() != '.')
|
||||||
tempLeafName.Append('.');
|
saltedTempLeafName.Append(PRUnichar('.'));
|
||||||
tempLeafName.Append(ext);
|
AppendUTF8toUTF16(ext, saltedTempLeafName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an additional .part to prevent the OS from running this file in the
|
// Add an additional .part to prevent the OS from running this file in the
|
||||||
// default application.
|
// default application.
|
||||||
tempLeafName.Append(NS_LITERAL_CSTRING(".part"));
|
saltedTempLeafName.Append(NS_LITERAL_STRING(".part"));
|
||||||
|
|
||||||
mTempFile->Append(NS_ConvertUTF8toUTF16(tempLeafName));
|
mTempFile->Append(saltedTempLeafName); // make this file unique!!!
|
||||||
// make this file unique!!!
|
|
||||||
mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
||||||
|
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
|
Loading…
Reference in New Issue
Block a user