Origin: coordinated disclosure
Description: Fix buffer overflow and memory leaks when storing exception text
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=756792
Index: icedtea-web-1.3/plugin/icedteanp/IcedTeaScriptablePluginObject.cc
===================================================================
--- icedtea-web-1.3.orig/plugin/icedteanp/IcedTeaScriptablePluginObject.cc	2012-08-27 14:36:42.000000000 -0500
+++ icedtea-web-1.3/plugin/icedteanp/IcedTeaScriptablePluginObject.cc	2012-11-06 06:49:01.000000000 -0600
@@ -591,10 +591,7 @@
 
     if (java_result->error_occurred)
     {
-        // error message must be allocated on heap
-        char* error_msg = (char*) malloc(java_result->error_msg->length()*sizeof(char));
-        strcpy(error_msg, java_result->error_msg->c_str());
-        browser_functions.setexception(npobj, error_msg);
+        browser_functions.setexception(npobj, java_result->error_msg->c_str());
         return false;
     }
 
@@ -853,11 +850,7 @@
         createJavaObjectFromVariant(instance, args[i], &id);
         if (id == "0")
         {
-            // error message must be allocated on heap
-            char* error_msg = (char*) malloc(1024*sizeof(char));
-            strcpy(error_msg, "Unable to create argument on Java side");
-
-            browser_functions.setexception(npobj, error_msg);
+            browser_functions.setexception(npobj, "Unable to create argument on Java side");
             return false;
         }
 
@@ -871,12 +864,7 @@
 
     if (java_result->error_occurred)
     {
-        // error message must be allocated on heap
-        int length = java_result->error_msg->length();
-        char* error_msg = (char*) malloc((length+1)*sizeof(char));
-        strcpy(error_msg, java_result->error_msg->c_str());
-
-        browser_functions.setexception(npobj, error_msg);
+        browser_functions.setexception(npobj, java_result->error_msg->c_str());
         return false;
     }
 
