Bug 615066 potential crash [@ nsPluginHost::HandleBadPlugin] if !aInstance
authortimeless@mozdev.org
Wed, 08 Dec 2010 12:22:10 +0000
changeset 58895 e741896a62ae01e23f682e9cafad80c98faf7926
parent 58894 395fac6a7de431827a5254d47ed92c5dafa8b489
child 58896 48a4773a6316b10b953f93ad3d1b842c5c9ca0dd
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs615066
milestone2.0b8pre
Bug 615066 potential crash [@ nsPluginHost::HandleBadPlugin] if !aInstance r=josh, a=josh
modules/plugin/base/src/nsPluginHost.cpp
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -3174,94 +3174,97 @@ NS_IMETHODIMP nsPluginHost::Observe(nsIS
 
 NS_IMETHODIMP
 nsPluginHost::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInstance)
 {
   // the |aLibrary| parameter is not needed anymore, after we added |aInstance| which
   // can also be used to look up the plugin name, but we cannot get rid of it because
   // the |nsIPluginHost| interface is deprecated which in fact means 'frozen'
 
-  nsresult rv = NS_OK;
-
-  NS_ASSERTION(PR_FALSE, "Plugin performed illegal operation");
+  NS_ERROR("Plugin performed illegal operation");
+  NS_ENSURE_ARG_POINTER(aInstance);
 
   if (mDontShowBadPluginMessage)
-    return rv;
+    return NS_OK;
 
   nsCOMPtr<nsIPluginInstanceOwner> owner;
-  if (aInstance)
-    aInstance->GetOwner(getter_AddRefs(owner));
+  aInstance->GetOwner(getter_AddRefs(owner));
 
   nsCOMPtr<nsIPrompt> prompt;
   GetPrompt(owner, getter_AddRefs(prompt));
-  if (prompt) {
-    nsCOMPtr<nsIStringBundleService> strings =
-      mozilla::services::GetStringBundleService();
-    if (!strings)
-      return NS_ERROR_FAILURE;
-
-    nsCOMPtr<nsIStringBundle> bundle;
-    rv = strings->CreateBundle(BRAND_PROPERTIES_URL, getter_AddRefs(bundle));
-    if (NS_FAILED(rv))
-      return rv;
-
-    nsXPIDLString brandName;
-    if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
-                                 getter_Copies(brandName))))
-      return rv;
-
-    rv = strings->CreateBundle(PLUGIN_PROPERTIES_URL, getter_AddRefs(bundle));
-    if (NS_FAILED(rv))
-      return rv;
-
-    nsXPIDLString title, message, checkboxMessage;
-    if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginTitle").get(),
-                                 getter_Copies(title))))
-      return rv;
-
-    const PRUnichar *formatStrings[] = { brandName.get() };
-    if (NS_FAILED(rv = bundle->FormatStringFromName(NS_LITERAL_STRING("BadPluginMessage").get(),
-                                 formatStrings, 1, getter_Copies(message))))
-      return rv;
-
-    if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage").get(),
-                                 getter_Copies(checkboxMessage))))
-      return rv;
-
-    nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
-
-    nsNPAPIPlugin *plugin = instance->GetPlugin();
-    if (!plugin)
-      return NS_ERROR_FAILURE;
-
-    nsPluginTag *pluginTag = TagForPlugin(plugin);
-
-    // add plugin name to the message
-    nsCString pluginname;
-    if (!pluginTag->mName.IsEmpty())
-      pluginname = pluginTag->mName;
-    else
-      pluginname = pluginTag->mFileName;
-
-    NS_ConvertUTF8toUTF16 msg(pluginname);
-    msg.AppendLiteral("\n\n");
-    msg.Append(message);
-
-    PRInt32 buttonPressed;
-    PRBool checkboxState = PR_FALSE;
-    rv = prompt->ConfirmEx(title, msg.get(),
-                         nsIPrompt::BUTTON_TITLE_OK * nsIPrompt::BUTTON_POS_0,
-                         nsnull, nsnull, nsnull,
-                         checkboxMessage, &checkboxState, &buttonPressed);
-
-
-    if (NS_SUCCEEDED(rv) && checkboxState)
-      mDontShowBadPluginMessage = PR_TRUE;
+  if (!prompt)
+    return NS_OK;
+
+  nsCOMPtr<nsIStringBundleService> strings =
+    mozilla::services::GetStringBundleService();
+  if (!strings)
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIStringBundle> bundle;
+  nsresult rv = strings->CreateBundle(BRAND_PROPERTIES_URL, getter_AddRefs(bundle));
+  if (NS_FAILED(rv))
+    return rv;
+
+  nsXPIDLString brandName;
+  rv = bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
+                                 getter_Copies(brandName));
+  if (NS_FAILED(rv))
+    return rv;
+
+  rv = strings->CreateBundle(PLUGIN_PROPERTIES_URL, getter_AddRefs(bundle));
+  if (NS_FAILED(rv))
+    return rv;
+
+  nsXPIDLString title, message, checkboxMessage;
+  rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginTitle").get(),
+                                 getter_Copies(title));
+  if (NS_FAILED(rv))
+    return rv;
+
+  const PRUnichar *formatStrings[] = { brandName.get() };
+  if (NS_FAILED(rv = bundle->FormatStringFromName(NS_LITERAL_STRING("BadPluginMessage").get(),
+                               formatStrings, 1, getter_Copies(message))))
+    return rv;
+
+  rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage").get(),
+                                 getter_Copies(checkboxMessage));
+  if (NS_FAILED(rv))
+    return rv;
+
+  nsNPAPIPluginInstance *instance = static_cast<nsNPAPIPluginInstance*>(aInstance);
+
+  nsNPAPIPlugin *plugin = instance->GetPlugin();
+  if (!plugin)
+    return NS_ERROR_FAILURE;
+
+  nsPluginTag *pluginTag = TagForPlugin(plugin);
+
+  // add plugin name to the message
+  nsCString pluginname;
+  if (!pluginTag->mName.IsEmpty()) {
+    pluginname = pluginTag->mName;
+  } else {
+    pluginname = pluginTag->mFileName;
   }
 
+  NS_ConvertUTF8toUTF16 msg(pluginname);
+  msg.AppendLiteral("\n\n");
+  msg.Append(message);
+
+  PRInt32 buttonPressed;
+  PRBool checkboxState = PR_FALSE;
+  rv = prompt->ConfirmEx(title, msg.get(),
+                       nsIPrompt::BUTTON_TITLE_OK * nsIPrompt::BUTTON_POS_0,
+                       nsnull, nsnull, nsnull,
+                       checkboxMessage, &checkboxState, &buttonPressed);
+
+
+  if (NS_SUCCEEDED(rv) && checkboxState)
+    mDontShowBadPluginMessage = PR_TRUE;
+
   return rv;
 }
 
 NS_IMETHODIMP
 nsPluginHost::ParsePostBufferToFixHeaders(const char *inPostData, PRUint32 inPostDataLen,
                                           char **outPostData, PRUint32 *outPostDataLen)
 {
   if (!inPostData || !outPostData || !outPostDataLen)