diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 6c874311602..b4b59067678 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -86,6 +86,15 @@ static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); #define XPINSTALL_BUNDLE_URL "chrome://xpinstall/locale/xpinstall.properties" +// filename length maximums +#ifdef XP_MAC +#define MAX_NAME_LENGTH 31 +#elif defined (XP_PC) +#define MAX_NAME_LENGTH 128 +#elif defined (XP_UNIX) +#define MAX_NAME_LENGTH 1024 //got this one from nsComponentManager.h +#endif + MOZ_DECL_CTOR_COUNTER(nsInstallInfo); nsInstallInfo::nsInstallInfo(nsIFileSpec* aFile, @@ -107,7 +116,7 @@ nsInstallInfo::nsInstallInfo(nsIFileSpec* aFile, nsInstallInfo::~nsInstallInfo() { - MOZ_COUNT_DTOR(nsInstallInfo); + MOZ_COUNT_DTOR(nsInstallInfo); } nsresult @@ -130,7 +139,7 @@ static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID); MOZ_DECL_CTOR_COUNTER(nsInstall); -nsInstall::nsInstall() +nsInstall::nsInstall(nsIZipReader * theJARFile) { MOZ_COUNT_CTOR(nsInstall); @@ -147,12 +156,12 @@ nsInstall::nsInstall() mJarFileLocation = ""; mInstallArguments = ""; + // mJarFileData is an opaque handle to the jarfile. - nsresult rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, kIZipReaderIID, - (void**) &mJarFileData); + mJarFileData = theJARFile; nsISoftwareUpdate *su; - rv = nsServiceManager::GetService(kSoftwareUpdateCID, + nsresult rv = nsServiceManager::GetService(kSoftwareUpdateCID, kISoftwareUpdateIID, (nsISupports**) &su); @@ -474,6 +483,12 @@ nsInstall::AddSubcomponent(const nsString& aRegName, *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); return NS_OK; } + + if(aTargetName.Length() > MAX_NAME_LENGTH) + { + *aReturn = SaveError( nsInstall::FILENAME_TOO_LONG ); + return NS_OK; + } PRInt32 result = SanityCheck(); @@ -1313,7 +1328,7 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis if (szRegPackageName == nsnull) { *aReturn = SaveError(nsInstall::OUT_OF_MEMORY); - return PR_FALSE; + return nsInstall::OUT_OF_MEMORY; } *szRegPackagePath = '0'; @@ -1351,7 +1366,7 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis if (mVersionInfo == nsnull) { *aReturn = nsInstall::OUT_OF_MEMORY; - return nsInstall::OUT_OF_MEMORY; + return SaveError(nsInstall::OUT_OF_MEMORY); } mVersionInfo->Init(aVersion); @@ -1361,20 +1376,9 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis if (mInstalledFiles == nsnull) { *aReturn = nsInstall::OUT_OF_MEMORY; - return nsInstall::OUT_OF_MEMORY; + return SaveError(nsInstall::OUT_OF_MEMORY); } - /* this function should also check security!!! */ - *aReturn = OpenJARFile(); - - if (*aReturn != nsInstall::SUCCESS) // XXX must use NS_SUCCEEDED macro! - { - /* if we can not continue with the javascript return a JAR error*/ - return -1; /* FIX: need real error code */ - } - - SaveError(*aReturn); - if (mNotifier) mNotifier->InstallStarted(mInstallURL.GetUnicode(), mUIName.GetUnicode()); @@ -2079,7 +2083,6 @@ void nsInstall::CleanUp(void) { nsInstallObject* ie; - CloseJARFile(); if ( mInstalledFiles != NULL ) { @@ -2165,33 +2168,6 @@ nsInstall::Confirm(nsString& string, PRBool* aReturn) } - -PRInt32 -nsInstall::OpenJARFile(void) -{ - nsresult rv; - nsCOMPtr file; - rv = NS_NewLocalFile(mJarFileLocation, getter_AddRefs(file)); // XXX until mJarFileLocation is an nsIFile - if (NS_FAILED(rv)) - return UNEXPECTED_ERROR; - rv = mJarFileData->Init(file); - if (NS_FAILED(rv)) - return UNEXPECTED_ERROR; - - rv = mJarFileData->Open(); - if (NS_FAILED(rv)) - return UNEXPECTED_ERROR; - - return SUCCESS; -} - -void -nsInstall::CloseJARFile(void) -{ - NS_IF_RELEASE(mJarFileData); -} - - // aJarFile - This is the filepath within the jar file. // aSuggestedName - This is the name that we should try to extract to. If we can, we will create a new temporary file. // aRealName - This is the name that we did extract to. This will be allocated by use and should be disposed by the caller. diff --git a/mozilla/xpinstall/src/nsInstall.h b/mozilla/xpinstall/src/nsInstall.h index c913fdd3f33..44e08230f4c 100644 --- a/mozilla/xpinstall/src/nsInstall.h +++ b/mozilla/xpinstall/src/nsInstall.h @@ -148,6 +148,7 @@ class nsInstall SOURCE_IS_DIRECTORY = -233, SOURCE_IS_FILE = -234, INSUFFICIENT_DISK_SPACE = -235, + FILENAME_TOO_LONG = -236, OUT_OF_MEMORY = -299, @@ -168,7 +169,7 @@ class nsInstall }; - nsInstall(); + nsInstall(nsIZipReader * theJARFile); virtual ~nsInstall(); PRInt32 SetScriptObject(void* aScriptObject); @@ -314,8 +315,6 @@ class nsInstall void CleanUp(); - PRInt32 OpenJARFile(void); - void CloseJARFile(void); PRInt32 ExtractDirEntries(const nsString& directory, nsVoidArray *paths); PRInt32 ScheduleForInstall(nsInstallObject* ob); diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index 7e4195f7904..8189feb4de6 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -104,7 +104,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, nsInstallVersion* oldVersion = new nsInstallVersion(); - if (newVersion == nsnull) + if (oldVersion == nsnull) { Recycle(qualifiedRegNameString); delete oldVersion; @@ -127,9 +127,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, { // the file to be installed is OLDER than what is on disk. // Don't install it. - Recycle(qualifiedRegNameString); mSkipInstall = PR_TRUE; - return; } } @@ -238,12 +236,12 @@ nsInstallFile::~nsInstallFile() */ PRInt32 nsInstallFile::Prepare() { - if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull ) - return nsInstall::INVALID_ARGUMENTS; - if (mSkipInstall) return nsInstall::SUCCESS; + if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull ) + return nsInstall::INVALID_ARGUMENTS; + return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtractedFile); } diff --git a/mozilla/xpinstall/src/nsJSInstall.cpp b/mozilla/xpinstall/src/nsJSInstall.cpp index df72293c4f0..7184cc09dd5 100644 --- a/mozilla/xpinstall/src/nsJSInstall.cpp +++ b/mozilla/xpinstall/src/nsJSInstall.cpp @@ -1793,6 +1793,7 @@ static JSConstDoubleSpec install_constants[] = { nsInstall::SOURCE_IS_DIRECTORY, "SOURCE_IS_DIRECTORY" }, { nsInstall::SOURCE_IS_FILE, "SOURCE_IS_FILE" }, { nsInstall::INSUFFICIENT_DISK_SPACE, "INSUFFICIENT_DISK_SPACE" }, + { nsInstall::FILENAME_TOO_LONG, "FILENAME_TOO_LONG" }, { nsInstall::GESTALT_UNKNOWN_ERR, "GESTALT_UNKNOWN_ERR" }, { nsInstall::GESTALT_INVALID_ARGUMENT, "GESTALT_INVALID_ARGUMENT" }, @@ -1912,7 +1913,8 @@ JSObject * InitXPInstallObjects(JSContext *jscontext, JSObject *global, const nsFileSpec& jarfile, const PRUnichar* url, - const PRUnichar* args) + const PRUnichar* args, + nsIZipReader * theJARFile) { JSObject *installObject = nsnull; nsInstall *nativeInstallObject; @@ -1943,7 +1945,7 @@ JSObject * InitXPInstallObjects(JSContext *jscontext, if ( PR_FALSE == JS_DefineConstDoubles(jscontext, installObject, install_constants) ) return nsnull; - nativeInstallObject = new nsInstall(); + nativeInstallObject = new nsInstall(theJARFile); nativeInstallObject->SetJarFileLocation(jarfile); nativeInstallObject->SetInstallArguments(args); diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index a2573640b68..cd5cefa8cf7 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -50,18 +50,18 @@ static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); - -extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, const nsFileSpec& jarfile, const PRUnichar* url, const PRUnichar* args); +extern JSObject *InitXPInstallObjects(JSContext *jscontext, JSObject *global, const nsFileSpec& jarfile, const PRUnichar* url, const PRUnichar* args, nsIZipReader* hZip); extern nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype); extern nsresult InitInstallTriggerGlobalClass(JSContext *jscontext, JSObject *global, void** prototype); // Defined in this file: static void XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); -static PRInt32 GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength); -static nsresult SetupInstallContext(const nsFileSpec& jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); +static PRInt32 GetInstallScriptFromJarfile(nsIZipReader* hZip, nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength); +static nsresult SetupInstallContext(nsIZipReader* hZip, const nsFileSpec& jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob); extern "C" void RunInstallOnThread(void *data); + /////////////////////////////////////////////////////////////////////////////////////////////// // Function name : XPInstallErrorReporter // Description : Prints error message to stdout @@ -121,23 +121,15 @@ XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report /////////////////////////////////////////////////////////////////////////////////////////////// static PRInt32 -GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength) +GetInstallScriptFromJarfile(nsIZipReader* hZip, nsFileSpec& jarFile, char** scriptBuffer, PRUint32 *scriptLength) { - nsCOMPtr hZip; PRInt32 result = NS_OK; *scriptBuffer = nsnull; *scriptLength = 0; - static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID); - static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID); - nsresult rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, kIZipReaderIID, - getter_AddRefs(hZip)); - if (NS_FAILED(rv)) - return nsInstall::CANT_READ_ARCHIVE; - nsCOMPtr jFile; - rv = NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); + nsresult rv = NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); if (NS_SUCCEEDED(rv)) rv = hZip->Init(jFile); @@ -207,6 +199,7 @@ GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 * // Function name : SetupInstallContext // Description : Creates a Javascript context and adds our xpinstall objects to it. // Return type : static nsresult +// Argument : nsIZipReader hZip - the handle to the open archive file // Argument : const char* jarFile - native filepath to where jar exists on disk // Argument : const PRUnichar* url - URL of where this package came from // Argument : const PRUnichar* args - any arguments passed into the javascript context @@ -214,7 +207,8 @@ GetInstallScriptFromJarfile(nsFileSpec& jarFile, char** scriptBuffer, PRUint32 * // Argument : JSContext **jsCX - Created context, destroy via JS_DestroyContext // Argument : JSObject **jsGlob - created global object /////////////////////////////////////////////////////////////////////////////////////////////// -static nsresult SetupInstallContext(const nsFileSpec& jarFile, +static nsresult SetupInstallContext(nsIZipReader* hZip, + const nsFileSpec& jarFile, const PRUnichar* url, const PRUnichar* args, JSRuntime *rt, @@ -239,7 +233,7 @@ static nsresult SetupInstallContext(const nsFileSpec& jarFile, JS_SetErrorReporter(cx, XPInstallErrorReporter); - glob = InitXPInstallObjects(cx, nsnull, jarFile, url, args); + glob = InitXPInstallObjects(cx, nsnull, jarFile, url, args, hZip); // Init standard classes JS_InitStandardClasses(cx, glob); @@ -298,17 +292,25 @@ extern "C" void RunInstallOnThread(void *data) PRUint32 scriptLength; JSRuntime *rt; - JSContext *cx; + JSContext *cx; JSObject *glob; + nsCOMPtr hZip; + + static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID); + static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID); + nsresult rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, kIZipReaderIID, + getter_AddRefs(hZip)); + + if (NS_FAILED(rv)) + return; + // we will plan on sending a failure status back from here unless we // find positive acknowledgement that the script sent the status PRInt32 finalStatus; PRBool sendStatus = PR_TRUE; nsIXPINotifier *notifier; - nsresult rv; - // lets set up an eventQ so that our xpcom/proxies will not have to: nsCOMPtr eventQ; @@ -343,7 +345,8 @@ extern "C" void RunInstallOnThread(void *data) rv = installInfo->GetLocalFile(jarpath); if (NS_SUCCEEDED(rv)) { - finalStatus = GetInstallScriptFromJarfile( jarpath, + finalStatus = GetInstallScriptFromJarfile( hZip, + jarpath, &scriptBuffer, &scriptLength); @@ -360,7 +363,7 @@ extern "C" void RunInstallOnThread(void *data) rt = JS_Init(4L * 1024L * 1024L); } - rv = SetupInstallContext( jarpath, + rv = SetupInstallContext( hZip, jarpath, url.GetUnicode(), args.GetUnicode(), rt, &cx, &glob);