bug 584582 - XP_TTOA not null terminating strings on Linux. r=bsmedberg, a=blocking
authorTed Mielczarek <ted.mielczarek@gmail.com>
Wed, 11 Aug 2010 10:57:44 -0400
changeset 50349 abf7063bba5170fef5ce788ad63ba7da1ce3d09b
parent 50348 15a2bbb890260bd8e1cc28306eddc47337663da8
child 50350 a16044df722356de0d3855079230c65a25b64fa2
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, blocking
bugs584582
milestone2.0b4pre
bug 584582 - XP_TTOA not null terminating strings on Linux. r=bsmedberg, a=blocking
modules/plugin/test/mochitest/Makefile.in
toolkit/crashreporter/Makefile.in
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/modules/plugin/test/mochitest/Makefile.in
+++ b/modules/plugin/test/mochitest/Makefile.in
@@ -105,26 +105,23 @@ endif
 
 _MOCHICHROME_FILES = \
   test_bug479979.xul \
   test_npruntime.xul   \
   test_privatemode.xul \
   test_wmode.xul \
   $(NULL)
 
-# Temporarily disable the tests on Linux, see bug 573290 and bug 583591.
-ifneq ($(OS_ARCH),Linux)
 ifdef MOZ_CRASHREPORTER
 _MOCHICHROME_FILES += \
   test_crash_notify.xul \
   test_crash_notify_no_report.xul \
   test_crash_submit.xul \
   $(NULL)
 endif
-endif
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 _MOCHICHROME_FILES += \
   test_convertpoint.xul \
   $(NULL)
 
 _MOCHITEST_FILES += \
   test_cocoa_window_focus.html \
--- a/toolkit/crashreporter/Makefile.in
+++ b/toolkit/crashreporter/Makefile.in
@@ -107,15 +107,12 @@ CPPSRCS = \
 
 FORCE_STATIC_LIB = 1
 
 EXTRA_JS_MODULES = \
   CrashSubmit.jsm \
   $(NULL)
 
 ifdef ENABLE_TESTS
-# Temporarily disable the tests on Linux, see bug 573290 and bug 583591
-ifneq ($(OS_ARCH),Linux)
 TOOL_DIRS = test
 endif
-endif
 
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -116,16 +116,17 @@ using mozilla::MutexAutoLock;
 namespace CrashReporter {
 
 #ifdef XP_WIN32
 typedef wchar_t XP_CHAR;
 typedef std::wstring xpstring;
 #define CONVERT_UTF16_TO_XP_CHAR(x) x
 #define CONVERT_XP_CHAR_TO_UTF16(x) x
 #define XP_STRLEN(x) wcslen(x)
+#define my_strlen strlen
 #define CRASH_REPORTER_FILENAME "crashreporter.exe"
 #define PATH_SEPARATOR "\\"
 #define XP_PATH_SEPARATOR L"\\"
 // sort of arbitrary, but MAX_PATH is kinda small
 #define XP_PATH_MAX 4096
 // "<reporter path>" "<minidump path>"
 #define CMDLINE_SIZE ((XP_PATH_MAX * 2) + 6)
 #ifdef _USE_32BIT_TIME_T
@@ -139,20 +140,21 @@ typedef std::string xpstring;
 #define CONVERT_UTF16_TO_XP_CHAR(x) NS_ConvertUTF16toUTF8(x)
 #define CONVERT_XP_CHAR_TO_UTF16(x) NS_ConvertUTF8toUTF16(x)
 #define CRASH_REPORTER_FILENAME "crashreporter"
 #define PATH_SEPARATOR "/"
 #define XP_PATH_SEPARATOR "/"
 #define XP_PATH_MAX PATH_MAX
 #ifdef XP_LINUX
 #define XP_STRLEN(x) my_strlen(x)
-#define XP_TTOA(time, buffer, base) my_itos(buffer, time, sizeof(buffer))
+#define XP_TTOA(time, buffer, base) my_timetostring(time, buffer, sizeof(buffer))
 #else
 #define XP_STRLEN(x) strlen(x)
 #define XP_TTOA(time, buffer, base) sprintf(buffer, "%ld", time)
+#define my_strlen strlen
 #define sys_close close
 #define sys_fork fork
 #define sys_open open
 #define sys_write write
 #endif
 #endif // XP_WIN32
 
 static const XP_CHAR dumpFileExtension[] = {'.', 'd', 'm', 'p',
@@ -218,16 +220,25 @@ static const char* kSubprocessBlacklist[
   "FramePoisonSize",
   "StartupTime",
   "URL"
 };
 
 
 #endif  // MOZ_IPC
 
+#ifdef XP_LINUX
+inline void
+my_timetostring(time_t t, char* buffer, size_t buffer_length)
+{
+  my_memset(buffer, 0, buffer_length);
+  my_itos(buffer, t, my_int_len(t));
+}
+#endif
+
 #ifdef XP_WIN
 static void
 CreateFileFromPath(const xpstring& path, nsILocalFile** file)
 {
   NS_NewLocalFile(nsDependentString(path.c_str()), PR_FALSE, file);
 }
 #else
 static void
@@ -289,21 +300,21 @@ bool MinidumpCallback(const XP_CHAR* dum
   time_t timeSinceLastCrash = 0;
   // stringified versions of the above
   char crashTimeString[32];
   int crashTimeStringLen = 0;
   char timeSinceLastCrashString[32];
   int timeSinceLastCrashStringLen = 0;
 
   XP_TTOA(crashTime, crashTimeString, 10);
-  crashTimeStringLen = strlen(crashTimeString);
+  crashTimeStringLen = my_strlen(crashTimeString);
   if (lastCrashTime != 0) {
     timeSinceLastCrash = crashTime - lastCrashTime;
     XP_TTOA(timeSinceLastCrash, timeSinceLastCrashString, 10);
-    timeSinceLastCrashStringLen = strlen(timeSinceLastCrashString);
+    timeSinceLastCrashStringLen = my_strlen(timeSinceLastCrashString);
   }
   // write crash time to file
   if (lastCrashTimeFilename[0] != 0) {
 #if defined(XP_WIN32)
     HANDLE hFile = CreateFile(lastCrashTimeFilename, GENERIC_WRITE, 0,
                               NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
                               NULL);
     if(hFile != INVALID_HANDLE_VALUE) {
@@ -562,17 +573,18 @@ nsresult SetExceptionHandler(nsILocalFil
                      true);
 #endif
 
   if (!gExceptionHandler)
     return NS_ERROR_OUT_OF_MEMORY;
 
   // store application start time
   char timeString[32];
-  XP_TTOA(time(NULL), timeString, 10);
+  time_t startupTime = time(NULL);
+  XP_TTOA(startupTime, timeString, 10);
   AnnotateCrashReport(NS_LITERAL_CSTRING("StartupTime"),
                       nsDependentCString(timeString));
 
 #if defined(XP_MACOSX)
   // On OS X, many testers like to see the OS crash reporting dialog
   // since it offers immediate stack traces.  We allow them to set
   // a default to pass exceptions to the OS handler.
   Boolean keyExistsAndHasValidFormat = false;