diff --git a/browser/locales/en-US/updater/updater.ini b/browser/locales/en-US/updater/updater.ini index 6bc731f1619c..cc4ae5405ec0 100644 --- a/browser/locales/en-US/updater/updater.ini +++ b/browser/locales/en-US/updater/updater.ini @@ -3,7 +3,6 @@ ; file, You can obtain one at http://mozilla.org/MPL/2.0/. ; This file is in the UTF-8 encoding -; All strings must be less than 600 chars. [Strings] TitleText=%MOZ_APP_DISPLAYNAME% Update InfoText=%MOZ_APP_DISPLAYNAME% is installing your updates and will start in a few moments… diff --git a/toolkit/components/maintenanceservice/serviceinstall.cpp b/toolkit/components/maintenanceservice/serviceinstall.cpp index eb02422fadfe..6f1e17646a47 100644 --- a/toolkit/components/maintenanceservice/serviceinstall.cpp +++ b/toolkit/components/maintenanceservice/serviceinstall.cpp @@ -55,13 +55,13 @@ static int ReadMaintenanceServiceStrings( // Read in the maintenance service description string if specified. const unsigned int kNumStrings = 1; const char* kServiceKeys = "MozillaMaintenanceDescription\0"; - char serviceStrings[kNumStrings][MAX_TEXT_LEN]; - int result = ReadStrings(path, kServiceKeys, kNumStrings, serviceStrings); + mozilla::UniquePtr serviceString; + int result = ReadStrings(path, kServiceKeys, kNumStrings, &serviceString); if (result != OK) { - serviceStrings[0][0] = '\0'; + results->serviceDescription = mozilla::MakeUnique(1); + results->serviceDescription.get()[0] = '\0'; } - strncpy(results->serviceDescription, serviceStrings[0], MAX_TEXT_LEN - 1); - results->serviceDescription[MAX_TEXT_LEN - 1] = '\0'; + results->serviceDescription.swap(serviceString); return result; } @@ -149,24 +149,26 @@ BOOL UpdateServiceDescription(SC_HANDLE serviceHandle) { MaintenanceServiceStringTable serviceStrings; int rv = ReadMaintenanceServiceStrings(updaterINIPath, &serviceStrings); - if (rv != OK || !strlen(serviceStrings.serviceDescription)) { + if (rv != OK || !strlen(serviceStrings.serviceDescription.get())) { LOG_WARN( ("updater.ini file does not contain a maintenance " "service description.")); return FALSE; } - WCHAR serviceDescription[MAX_TEXT_LEN]; - if (!MultiByteToWideChar( - CP_UTF8, 0, serviceStrings.serviceDescription, -1, serviceDescription, - sizeof(serviceDescription) / sizeof(serviceDescription[0]))) { + int bufferSize = MultiByteToWideChar( + CP_UTF8, 0, serviceStrings.serviceDescription.get(), -1, nullptr, 0); + mozilla::UniquePtr serviceDescription = + mozilla::MakeUnique(bufferSize); + if (!MultiByteToWideChar(CP_UTF8, 0, serviceStrings.serviceDescription.get(), + -1, serviceDescription.get(), bufferSize)) { LOG_WARN(("Could not convert description to wide string format. (%d)", GetLastError())); return FALSE; } SERVICE_DESCRIPTIONW descriptionConfig; - descriptionConfig.lpDescription = serviceDescription; + descriptionConfig.lpDescription = serviceDescription.get(); if (!ChangeServiceConfig2W(serviceHandle, SERVICE_CONFIG_DESCRIPTION, &descriptionConfig)) { LOG_WARN(("Could not change service config. (%d)", GetLastError())); diff --git a/toolkit/components/maintenanceservice/serviceinstall.h b/toolkit/components/maintenanceservice/serviceinstall.h index 8cc23a793018..735bebd67f6a 100644 --- a/toolkit/components/maintenanceservice/serviceinstall.h +++ b/toolkit/components/maintenanceservice/serviceinstall.h @@ -15,5 +15,5 @@ DWORD SetUserAccessServiceDACL(SC_HANDLE hService, PACL& pNewAcl, PSECURITY_DESCRIPTOR psd); struct MaintenanceServiceStringTable { - char serviceDescription[MAX_TEXT_LEN]; + mozilla::UniquePtr serviceDescription; }; diff --git a/toolkit/mozapps/defaultagent/Notification.cpp b/toolkit/mozapps/defaultagent/Notification.cpp index dc1fcbd68d1e..140f92e39b55 100644 --- a/toolkit/mozapps/defaultagent/Notification.cpp +++ b/toolkit/mozapps/defaultagent/Notification.cpp @@ -27,10 +27,6 @@ #define SEVEN_DAYS_IN_SECONDS (7 * 24 * 60 * 60) -// Rename this constant from readstrings.h so it is more clear what it is -// in this context -#define MAX_INI_STRING_LEN MAX_TEXT_LEN - // If the notification hasn't been activated or dismissed within 30 minutes, // stop waiting for it. #define NOTIFICATION_WAIT_TIMEOUT_MS (30 * 60 * 1000) @@ -113,35 +109,43 @@ struct Strings { } }; -// Gets a string out of the specified INI file. This function should not be used -// for localized strings. -// Returns true on success, false on failure -static bool GetString(const wchar_t* iniPath, const wchar_t* section, - const wchar_t* key, - mozilla::UniquePtr& toastString) { - toastString = mozilla::MakeUnique(MAX_INI_STRING_LEN); - DWORD stringLength = GetPrivateProfileStringW( - section, key, nullptr, toastString.get(), MAX_INI_STRING_LEN, iniPath); - if (stringLength <= 0) { - LOG_ERROR_MESSAGE(L"Unable to retrieve string: section=%s, key=%s", section, - key); +// Returns true on success, false on failure. +static bool ConvertToWide(const mozilla::UniquePtr& toConvert, + mozilla::UniquePtr& result) { + int bufferSize = + MultiByteToWideChar(CP_UTF8, 0, toConvert.get(), -1, nullptr, 0); + result = mozilla::MakeUnique(bufferSize); + int charsWritten = MultiByteToWideChar(CP_UTF8, 0, toConvert.get(), -1, + result.get(), bufferSize); + if (charsWritten == 0) { + LOG_ERROR_MESSAGE(L"Unable to widen string: %#X", GetLastError()); return false; } return true; } -// Returns true on success, false on failure. -static bool ConvertToWide(const char* toConvert, - mozilla::UniquePtr& result) { - int bufferSize = MultiByteToWideChar(CP_UTF8, 0, toConvert, -1, nullptr, 0); - result = mozilla::MakeUnique(bufferSize); - int charsWritten = - MultiByteToWideChar(CP_UTF8, 0, toConvert, -1, result.get(), bufferSize); - if (charsWritten == 0) { - LOG_ERROR_MESSAGE(L"Unable to widen localized string: %#X", GetLastError()); +// Gets a string out of the specified INI file. +// Returns true on success, false on failure +static bool GetString(const wchar_t* iniPath, const char* section, + const char* key, + mozilla::UniquePtr& toastString) { + const unsigned int stringCount = 1; + + size_t keyLen = strlen(key); + mozilla::UniquePtr keyList = mozilla::MakeUnique(keyLen + 2); + strcpy(keyList.get(), key); + keyList.get()[keyLen + 1] = '\0'; + + mozilla::UniquePtr narrowString; + int result = + ReadStrings(iniPath, keyList.get(), stringCount, &narrowString, section); + if (result != OK) { + LOG_ERROR_MESSAGE( + L"Unable to retrieve INI string: section=%S, key=%S, result=%d", + section, key, result); return false; } - return true; + return ConvertToWide(narrowString, toastString); } // Gets all strings out of the localized INI file. @@ -172,7 +176,7 @@ static bool GetStrings(Strings& strings) { "DefaultBrowserNotificationRemindMeLater\0" "DefaultBrowserNotificationMakeFirefoxDefault\0" "DefaultBrowserNotificationDontShowAgain\0"; - char localizedStrings[stringCount][MAX_INI_STRING_LEN]; + mozilla::UniquePtr localizedStrings[stringCount]; int result = ReadStrings(iniPath.get(), keys, stringCount, localizedStrings); if (result != OK) { LOG_ERROR_MESSAGE(L"Unable to read localized strings: %d", result); @@ -183,15 +187,15 @@ static bool GetStrings(Strings& strings) { ConvertToWide(localizedStrings[1], strings.initialToast.text2) && ConvertToWide(localizedStrings[2], strings.initialToast.action1) && ConvertToWide(localizedStrings[3], strings.initialToast.action2) && - GetString(iniPath.get(), L"Nonlocalized", - L"InitialToastRelativeImagePath", + GetString(iniPath.get(), "Nonlocalized", + "InitialToastRelativeImagePath", strings.initialToast.relImagePath) && ConvertToWide(localizedStrings[0], strings.followupToast.text1) && ConvertToWide(localizedStrings[1], strings.followupToast.text2) && ConvertToWide(localizedStrings[4], strings.followupToast.action1) && ConvertToWide(localizedStrings[3], strings.followupToast.action2) && - GetString(iniPath.get(), L"Nonlocalized", - L"FollowupToastRelativeImagePath", + GetString(iniPath.get(), "Nonlocalized", + "FollowupToastRelativeImagePath", strings.followupToast.relImagePath); } @@ -507,7 +511,7 @@ bool IsEnglish() { installPath.get()); mozilla::UniquePtr firefoxLocale; - if (!GetString(iniPath.get(), L"locale", L"locale", firefoxLocale)) { + if (!GetString(iniPath.get(), "locale", "locale", firefoxLocale)) { return false; } diff --git a/toolkit/mozapps/defaultagent/defaultagent.ini b/toolkit/mozapps/defaultagent/defaultagent.ini index 0a8ce57067a7..09a674544366 100644 --- a/toolkit/mozapps/defaultagent/defaultagent.ini +++ b/toolkit/mozapps/defaultagent/defaultagent.ini @@ -3,7 +3,6 @@ ; file, You can obtain one at http://mozilla.org/MPL/2.0/. ; This file is in the UTF-8 encoding -; All strings must be less than 600 chars. [Strings] DefaultBrowserNotificationTitle=Switch back to %MOZ_APP_DISPLAYNAME%? DefaultBrowserNotificationText=Your default browser was recently changed. diff --git a/toolkit/mozapps/defaultagent/defaultagent_append.ini b/toolkit/mozapps/defaultagent/defaultagent_append.ini index 6f5c1116f0e6..b52d9d11c3ad 100644 --- a/toolkit/mozapps/defaultagent/defaultagent_append.ini +++ b/toolkit/mozapps/defaultagent/defaultagent_append.ini @@ -2,8 +2,6 @@ ; IMPORTANT: This file should always start with a newline in case a locale ; provided INI does not end with a newline. -; All strings must be less than 600 chars. - [Nonlocalized] InitialToastRelativeImagePath=browser/VisualElements/VisualElements_150.png FollowupToastRelativeImagePath=browser/VisualElements/VisualElements_150.png diff --git a/toolkit/mozapps/update/common/readstrings.cpp b/toolkit/mozapps/update/common/readstrings.cpp index 6d909ca9654d..20d02dee7521 100644 --- a/toolkit/mozapps/update/common/readstrings.cpp +++ b/toolkit/mozapps/update/common/readstrings.cpp @@ -123,12 +123,13 @@ static int find_key(const char* keyList, char* key) { * @param keyList List of zero-delimited keys ending with two zero characters * @param numStrings Number of strings to read into results buffer - must be * equal to the number of keys - * @param results Two-dimensional array of strings to be filled in the same - * order as the keys provided + * @param results Array of strings. Array's length must be equal to + * numStrings. Each string will be populated with the value + * corresponding to the key with the same index in keyList. * @param section Optional name of the section to read; defaults to "Strings" */ int ReadStrings(const NS_tchar* path, const char* keyList, - unsigned int numStrings, char results[][MAX_TEXT_LEN], + unsigned int numStrings, mozilla::UniquePtr* results, const char* section) { AutoFILE fp(NS_tfopen(path, OPEN_MODE)); @@ -216,8 +217,10 @@ int ReadStrings(const NS_tchar* path, const char* keyList, int keyIndex = find_key(keyList, key); if (keyIndex >= 0 && (unsigned int)keyIndex < numStrings) { - strncpy(results[keyIndex], token, MAX_TEXT_LEN - 1); - results[keyIndex][MAX_TEXT_LEN - 1] = '\0'; + size_t valueSize = strlen(token) + 1; + results[keyIndex] = mozilla::MakeUnique(valueSize); + + strcpy(results[keyIndex].get(), token); read++; } } @@ -230,14 +233,14 @@ int ReadStrings(const NS_tchar* path, const char* keyList, int ReadStrings(const NS_tchar* path, StringTable* results) { const unsigned int kNumStrings = 2; const char* kUpdaterKeys = "Title\0Info\0"; - char updater_strings[kNumStrings][MAX_TEXT_LEN]; + mozilla::UniquePtr updater_strings[kNumStrings]; int result = ReadStrings(path, kUpdaterKeys, kNumStrings, updater_strings); - strncpy(results->title, updater_strings[0], MAX_TEXT_LEN - 1); - results->title[MAX_TEXT_LEN - 1] = '\0'; - strncpy(results->info, updater_strings[1], MAX_TEXT_LEN - 1); - results->info[MAX_TEXT_LEN - 1] = '\0'; + if (result == OK) { + results->title.swap(updater_strings[0]); + results->info.swap(updater_strings[1]); + } return result; } diff --git a/toolkit/mozapps/update/common/readstrings.h b/toolkit/mozapps/update/common/readstrings.h index 836a743f056e..9ff1b7f972cc 100644 --- a/toolkit/mozapps/update/common/readstrings.h +++ b/toolkit/mozapps/update/common/readstrings.h @@ -7,7 +7,7 @@ #ifndef READSTRINGS_H__ #define READSTRINGS_H__ -#define MAX_TEXT_LEN 600 +#include "mozilla/UniquePtr.h" #ifdef XP_WIN # include @@ -16,13 +16,9 @@ typedef WCHAR NS_tchar; typedef char NS_tchar; #endif -#ifndef NULL -# define NULL 0 -#endif - struct StringTable { - char title[MAX_TEXT_LEN]; - char info[MAX_TEXT_LEN]; + mozilla::UniquePtr title; + mozilla::UniquePtr info; }; /** @@ -35,7 +31,7 @@ int ReadStrings(const NS_tchar* path, StringTable* results); * given .ini */ int ReadStrings(const NS_tchar* path, const char* keyList, - unsigned int numStrings, char results[][MAX_TEXT_LEN], + unsigned int numStrings, mozilla::UniquePtr* results, const char* section = nullptr); #endif // READSTRINGS_H__ diff --git a/toolkit/mozapps/update/tests/TestAUSReadStrings.cpp b/toolkit/mozapps/update/tests/TestAUSReadStrings.cpp index 40d739af4c6b..3dce39c61ff7 100644 --- a/toolkit/mozapps/update/tests/TestAUSReadStrings.cpp +++ b/toolkit/mozapps/update/tests/TestAUSReadStrings.cpp @@ -95,7 +95,7 @@ int NS_main(int argc, NS_tchar** argv) { argv[0]); retval = ReadStrings(inifile, &testStrings); if (retval == OK) { - if (strcmp(testStrings.title, + if (strcmp(testStrings.title.get(), "Title Test - \xD0\x98\xD1\x81\xD0\xBF\xD1\x8B" "\xD1\x82\xD0\xB0\xD0\xBD\xD0\xB8\xD0\xB5 " "\xCE\x94\xCE\xBF\xCE\xBA\xCE\xB9\xCE\xBC\xCE\xAE " @@ -106,7 +106,7 @@ int NS_main(int argc, NS_tchar** argv) { fail("%s | Title ini value incorrect (check 3)", TEST_NAME); } - if (strcmp(testStrings.info, + if (strcmp(testStrings.info.get(), "Info Test - \xD0\x98\xD1\x81\xD0\xBF\xD1\x8B" "\xD1\x82\xD0\xB0\xD0\xBD\xD0\xB8\xD0\xB5 " "\xCE\x94\xCE\xBF\xCE\xBA\xCE\xB9\xCE\xBC\xCE\xAE " @@ -156,7 +156,7 @@ int NS_main(int argc, NS_tchar** argv) { retval = ReadStrings(inifile, "Title\0", 1, &testStrings.title, "BogusSection2"); if (retval == OK) { - if (strcmp(testStrings.title, "Bogus Title") != 0) { + if (strcmp(testStrings.title.get(), "Bogus Title") != 0) { rv = 27; fail("%s | Title ini value incorrect (check 9)", TEST_NAME); } @@ -165,6 +165,43 @@ int NS_main(int argc, NS_tchar** argv) { rv = 28; } + // Test reading an exceedingly long string + NS_tsnprintf(inifile, ArrayLength(inifile), NS_T("%sTestAUSReadStrings4.ini"), + argv[0]); + retval = ReadStrings(inifile, "LongValue\0", 1, &testStrings.title); + const char* expectedValue = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id " + "ipsum condimentum, faucibus ante porta, vehicula metus. Nunc nec luctus " + "lorem. Nunc mattis viverra nisl, eu ornare dui feugiat id. Aenean " + "commodo ligula porttitor elit aliquam, ut luctus nunc aliquam. In eu " + "eros at nunc pulvinar porta. Praesent porta felis vitae massa " + "sollicitudin, a vestibulum dolor rutrum. Aenean finibus, felis ac " + "dictum hendrerit, ligula arcu semper enim, rhoncus consequat arcu orci " + "nec est. Sed auctor hendrerit rhoncus. Maecenas dignissim lorem et " + "tellus maximus, sit amet pretium urna imperdiet. Duis ut libero " + "volutpat, rhoncus mi non, placerat lacus. Nunc id tortor in quam " + "lacinia luctus. Nam eu maximus ipsum, eu bibendum enim. Ut iaculis " + "maximus ipsum in condimentum. Aliquam tellus nulla, congue quis pretium " + "a, posuere quis ligula. Donec vel quam ipsum. Pellentesque congue urna " + "eget porttitor pulvinar. Proin non risus lacus. Vestibulum molestie et " + "ligula sit amet pellentesque. Phasellus luctus auctor lorem, vel " + "dapibus ante iaculis sed. Cras ligula ex, vehicula a dui vel, posuere " + "fermentum elit. Vestibulum et nisi at libero maximus interdum a non ex. " + "Ut ut leo in metus convallis porta a et libero. Pellentesque fringilla " + "dolor sit amet eleifend fermentum. Quisque blandit dolor facilisis " + "purus vulputate sodales eget ac arcu. Nulla pulvinar feugiat accumsan. " + "Phasellus auctor nisl eget diam auctor, sit amet imperdiet mauris " + "condimentum. In a risus ut felis lobortis facilisis."; + if (retval == OK) { + if (strcmp(testStrings.title.get(), expectedValue) != 0) { + rv = 29; + fail("%s | LongValue ini value incorrect (check 10)", TEST_NAME); + } + } else { + fail("%s | ReadStrings returned %i (check 11)", TEST_NAME, retval); + rv = 30; + } + if (rv == 0) { printf("TEST-PASS | %s | all checks passed\n", TEST_NAME); } else { diff --git a/toolkit/mozapps/update/tests/TestAUSReadStrings4.ini b/toolkit/mozapps/update/tests/TestAUSReadStrings4.ini new file mode 100644 index 000000000000..b930455e8b05 --- /dev/null +++ b/toolkit/mozapps/update/tests/TestAUSReadStrings4.ini @@ -0,0 +1,5 @@ +; This file is in the UTF-8 encoding + +[Strings] + +LongValue=Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id ipsum condimentum, faucibus ante porta, vehicula metus. Nunc nec luctus lorem. Nunc mattis viverra nisl, eu ornare dui feugiat id. Aenean commodo ligula porttitor elit aliquam, ut luctus nunc aliquam. In eu eros at nunc pulvinar porta. Praesent porta felis vitae massa sollicitudin, a vestibulum dolor rutrum. Aenean finibus, felis ac dictum hendrerit, ligula arcu semper enim, rhoncus consequat arcu orci nec est. Sed auctor hendrerit rhoncus. Maecenas dignissim lorem et tellus maximus, sit amet pretium urna imperdiet. Duis ut libero volutpat, rhoncus mi non, placerat lacus. Nunc id tortor in quam lacinia luctus. Nam eu maximus ipsum, eu bibendum enim. Ut iaculis maximus ipsum in condimentum. Aliquam tellus nulla, congue quis pretium a, posuere quis ligula. Donec vel quam ipsum. Pellentesque congue urna eget porttitor pulvinar. Proin non risus lacus. Vestibulum molestie et ligula sit amet pellentesque. Phasellus luctus auctor lorem, vel dapibus ante iaculis sed. Cras ligula ex, vehicula a dui vel, posuere fermentum elit. Vestibulum et nisi at libero maximus interdum a non ex. Ut ut leo in metus convallis porta a et libero. Pellentesque fringilla dolor sit amet eleifend fermentum. Quisque blandit dolor facilisis purus vulputate sodales eget ac arcu. Nulla pulvinar feugiat accumsan. Phasellus auctor nisl eget diam auctor, sit amet imperdiet mauris condimentum. In a risus ut felis lobortis facilisis. diff --git a/toolkit/mozapps/update/tests/moz.build b/toolkit/mozapps/update/tests/moz.build index 669fb13f060b..a047f5b494a3 100644 --- a/toolkit/mozapps/update/tests/moz.build +++ b/toolkit/mozapps/update/tests/moz.build @@ -98,6 +98,7 @@ FINAL_TARGET_FILES += [ 'TestAUSReadStrings1.ini', 'TestAUSReadStrings2.ini', 'TestAUSReadStrings3.ini', + 'TestAUSReadStrings4.ini', ] FINAL_TARGET_PP_FILES += [ diff --git a/toolkit/mozapps/update/tests/unit_aus_update/ausReadStrings.js b/toolkit/mozapps/update/tests/unit_aus_update/ausReadStrings.js index 31e6350ef3bb..ed331f5ebc34 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/ausReadStrings.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/ausReadStrings.js @@ -16,6 +16,7 @@ function run_test() { "TestAUSReadStrings1.ini", "TestAUSReadStrings2.ini", "TestAUSReadStrings3.ini", + "TestAUSReadStrings4.ini", ]; for (let i = 0; i < paths.length; i++) { let file = do_get_file("../data/" + paths[i]); diff --git a/toolkit/mozapps/update/updater/launchchild_osx.mm b/toolkit/mozapps/update/updater/launchchild_osx.mm index f327e1f92a3a..95c39f3d0e09 100644 --- a/toolkit/mozapps/update/updater/launchchild_osx.mm +++ b/toolkit/mozapps/update/updater/launchchild_osx.mm @@ -52,15 +52,15 @@ void LaunchMacPostProcess(const char* aAppBundle) { } int readResult; - char values[2][MAX_TEXT_LEN]; + mozilla::UniquePtr values[2]; readResult = ReadStrings([iniPath UTF8String], "ExeRelPath\0ExeArg\0", 2, values, "PostUpdateMac"); if (readResult) { return; } - NSString* exeRelPath = [NSString stringWithUTF8String:values[0]]; - NSString* exeArg = [NSString stringWithUTF8String:values[1]]; + NSString* exeRelPath = [NSString stringWithUTF8String:values[0].get()]; + NSString* exeArg = [NSString stringWithUTF8String:values[1].get()]; if (!exeArg || !exeRelPath) { return; } @@ -75,15 +75,15 @@ void LaunchMacPostProcess(const char* aAppBundle) { NSString* exeFullPath = [NSString stringWithUTF8String:aAppBundle]; exeFullPath = [exeFullPath stringByAppendingPathComponent:exeRelPath]; - char optVals[1][MAX_TEXT_LEN]; - readResult = ReadStrings([iniPath UTF8String], "ExeAsync\0", 1, optVals, "PostUpdateMac"); + mozilla::UniquePtr optVal; + readResult = ReadStrings([iniPath UTF8String], "ExeAsync\0", 1, &optVal, "PostUpdateMac"); NSTask* task = [[NSTask alloc] init]; [task setLaunchPath:exeFullPath]; [task setArguments:[NSArray arrayWithObject:exeArg]]; [task launch]; if (!readResult) { - NSString* exeAsync = [NSString stringWithUTF8String:optVals[0]]; + NSString* exeAsync = [NSString stringWithUTF8String:optVal.get()]; if ([exeAsync isEqualToString:@"false"]) { [task waitUntilExit]; } diff --git a/toolkit/mozapps/update/updater/progressui_gtk.cpp b/toolkit/mozapps/update/updater/progressui_gtk.cpp index f4ca2d40c2d7..922ca6f426bd 100644 --- a/toolkit/mozapps/update/updater/progressui_gtk.cpp +++ b/toolkit/mozapps/update/updater/progressui_gtk.cpp @@ -86,7 +86,7 @@ int ShowProgressUI() { g_signal_connect(G_OBJECT(sWin), "delete_event", G_CALLBACK(OnDeleteEvent), nullptr); - gtk_window_set_title(GTK_WINDOW(sWin), sStrings.title); + gtk_window_set_title(GTK_WINDOW(sWin), sStrings.title.get()); gtk_window_set_type_hint(GTK_WINDOW(sWin), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_position(GTK_WINDOW(sWin), GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_resizable(GTK_WINDOW(sWin), FALSE); @@ -96,7 +96,7 @@ int ShowProgressUI() { g_object_unref(sPixbuf); GtkWidget* vbox = gtk_vbox_new(TRUE, 6); - sLabel = gtk_label_new(sStrings.info); + sLabel = gtk_label_new(sStrings.info.get()); gtk_misc_set_alignment(GTK_MISC(sLabel), 0.0f, 0.0f); sProgressBar = gtk_progress_bar_new(); diff --git a/toolkit/mozapps/update/updater/progressui_osx.mm b/toolkit/mozapps/update/updater/progressui_osx.mm index 4dba9be51a38..84cbd7fdb937 100644 --- a/toolkit/mozapps/update/updater/progressui_osx.mm +++ b/toolkit/mozapps/update/updater/progressui_osx.mm @@ -31,8 +31,8 @@ static const char* sUpdatePath; - (void)awakeFromNib { NSWindow* w = [progressBar window]; - [w setTitle:[NSString stringWithUTF8String:sLabels.title]]; - [progressTextField setStringValue:[NSString stringWithUTF8String:sLabels.info]]; + [w setTitle:[NSString stringWithUTF8String:sLabels.title.get()]]; + [progressTextField setStringValue:[NSString stringWithUTF8String:sLabels.info.get()]]; NSRect origTextFrame = [progressTextField frame]; [progressTextField sizeToFit]; @@ -111,12 +111,6 @@ int ShowProgressUI(bool indeterminate) { return -1; } - // Continue the update without showing the Progress UI if any of the supplied - // strings are larger than MAX_TEXT_LEN (Bug 628829). - if (!(strlen(sLabels.title) < MAX_TEXT_LEN - 1 && strlen(sLabels.info) < MAX_TEXT_LEN - 1)) { - return -1; - } - sIndeterminate = indeterminate; [NSApplication sharedApplication]; [[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:nil]; diff --git a/toolkit/mozapps/update/updater/progressui_win.cpp b/toolkit/mozapps/update/updater/progressui_win.cpp index 83335e82f48f..51bd2d8cce5d 100644 --- a/toolkit/mozapps/update/updater/progressui_win.cpp +++ b/toolkit/mozapps/update/updater/progressui_win.cpp @@ -94,16 +94,22 @@ static void CenterDialog(HWND hDlg) { } static void InitDialog(HWND hDlg) { - WCHAR szwTitle[MAX_TEXT_LEN]; - WCHAR szwInfo[MAX_TEXT_LEN]; + mozilla::UniquePtr szwTitle; + mozilla::UniquePtr szwInfo; - MultiByteToWideChar(CP_UTF8, 0, sUIStrings.title, -1, szwTitle, - sizeof(szwTitle) / sizeof(szwTitle[0])); - MultiByteToWideChar(CP_UTF8, 0, sUIStrings.info, -1, szwInfo, - sizeof(szwInfo) / sizeof(szwInfo[0])); + int bufferSize = + MultiByteToWideChar(CP_UTF8, 0, sUIStrings.title.get(), -1, nullptr, 0); + szwTitle = mozilla::MakeUnique(bufferSize); + MultiByteToWideChar(CP_UTF8, 0, sUIStrings.title.get(), -1, szwTitle.get(), + bufferSize); + bufferSize = + MultiByteToWideChar(CP_UTF8, 0, sUIStrings.info.get(), -1, nullptr, 0); + szwInfo = mozilla::MakeUnique(bufferSize); + MultiByteToWideChar(CP_UTF8, 0, sUIStrings.info.get(), -1, szwInfo.get(), + bufferSize); - SetWindowTextW(hDlg, szwTitle); - SetWindowTextW(GetDlgItem(hDlg, IDC_INFO), szwInfo); + SetWindowTextW(hDlg, szwTitle.get()); + SetWindowTextW(GetDlgItem(hDlg, IDC_INFO), szwInfo.get()); // Set dialog icon HICON hIcon = LoadIcon(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDI_DIALOG)); @@ -134,7 +140,7 @@ static void InitDialog(HWND hDlg) { // Measure the space needed for the text on a single line. DT_CALCRECT means // nothing is drawn. - if (DrawText(hDCInfo, szwInfo, -1, &textSize, + if (DrawText(hDCInfo, szwInfo.get(), -1, &textSize, DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE)) { GetClientRect(hWndInfo, &infoSize); SIZE extra; diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp index da15532e127f..02e35ed81aa2 100644 --- a/toolkit/mozapps/update/updater/updater.cpp +++ b/toolkit/mozapps/update/updater/updater.cpp @@ -181,9 +181,12 @@ class AutoFile { }; struct MARChannelStringTable { - MARChannelStringTable() { MARChannelID[0] = '\0'; } + MARChannelStringTable() { + MARChannelID = mozilla::MakeUnique(1); + MARChannelID[0] = '\0'; + } - char MARChannelID[MAX_TEXT_LEN]; + mozilla::UniquePtr MARChannelID; }; //----------------------------------------------------------------------------- @@ -2471,13 +2474,8 @@ static int ReadMARChannelIDs(const NS_tchar* path, MARChannelStringTable* results) { const unsigned int kNumStrings = 1; const char* kUpdaterKeys = "ACCEPTED_MAR_CHANNEL_IDS\0"; - char updater_strings[kNumStrings][MAX_TEXT_LEN]; - - int result = - ReadStrings(path, kUpdaterKeys, kNumStrings, updater_strings, "Settings"); - - strncpy(results->MARChannelID, updater_strings[0], MAX_TEXT_LEN - 1); - results->MARChannelID[MAX_TEXT_LEN - 1] = 0; + int result = ReadStrings(path, kUpdaterKeys, kNumStrings, + &results->MARChannelID, "Settings"); return result; } @@ -2507,7 +2505,7 @@ static void UpdateThreadFunc(void* param) { if (rv == OK) { if (rv == OK) { - NS_tchar updateSettingsPath[MAX_TEXT_LEN]; + NS_tchar updateSettingsPath[MAXPATHLEN]; NS_tsnprintf(updateSettingsPath, sizeof(updateSettingsPath) / sizeof(updateSettingsPath[0]), # ifdef XP_MACOSX @@ -2520,8 +2518,8 @@ static void UpdateThreadFunc(void* param) { if (ReadMARChannelIDs(updateSettingsPath, &MARStrings) != OK) { rv = UPDATE_SETTINGS_FILE_CHANNEL; } else { - rv = gArchiveReader.VerifyProductInformation(MARStrings.MARChannelID, - MOZ_APP_VERSION); + rv = gArchiveReader.VerifyProductInformation( + MARStrings.MARChannelID.get(), MOZ_APP_VERSION); } } }