Commit 2249a37b authored by av%netscape.com's avatar av%netscape.com
Browse files

Fixing bug 108246 -- special chars in plugin property strings break our plugin...

Fixing bug 108246 -- special chars in plugin property strings break our plugin management mechanism, r=dp, sr=dveditz
parent 8435bcef
Loading
Loading
Loading
Loading
+68 −43
Original line number Diff line number Diff line
@@ -2884,8 +2884,12 @@ NS_IMETHODIMP nsPluginHostImpl::RegisterPlugin(REFNSIID aCID,
  rv = registry->AddSubtree(nsIRegistry::Common, path.get(), &pluginKey);
  if (NS_FAILED(rv)) return rv;

  registry->SetStringUTF8(pluginKey, kPluginsNameKey, aPluginName);
  registry->SetStringUTF8(pluginKey, kPluginsDescKey, aDescription);
  // we use SetBytes instead of SetString to address special character issue, see Mozilla bug 108246
  if(aPluginName)
    registry->SetBytesUTF8(pluginKey, kPluginsNameKey, nsCRT::strlen(aPluginName) + 1, (PRUint8 *)aPluginName);

  if(aDescription)
    registry->SetBytesUTF8(pluginKey, kPluginsDescKey, nsCRT::strlen(aDescription) + 1, (PRUint8 *)aDescription);

  for (PRInt32 i = 0; i < aCount; ++i) {
    nsCAutoString mimepath;
@@ -2895,7 +2899,12 @@ NS_IMETHODIMP nsPluginHostImpl::RegisterPlugin(REFNSIID aCID,
    registry->AddSubtree(pluginKey, mimepath.get(), &key);

    registry->SetStringUTF8(key, kPluginsMimeTypeKey, aMimeTypes[i]);
    registry->SetStringUTF8(key, kPluginsMimeDescKey, aMimeDescriptions[i]);

    if(aMimeDescriptions[i])
      registry->SetBytesUTF8(key, kPluginsMimeDescKey, 
                             nsCRT::strlen(aMimeDescriptions[i]) + 1, 
                             (PRUint8 *)aMimeDescriptions[i]);

    registry->SetStringUTF8(key, kPluginsMimeExtKey, aFileExtensions[i]);
  }

@@ -4725,11 +4734,12 @@ LoadXPCOMPlugin(nsIRegistry* aRegistry,
  // The name, description, MIME types, MIME descriptions, and
  // supported file extensions will all hang off of the plugin's key
  // in the registry. Pull these out now.
  nsXPIDLCString name;
  aRegistry->GetStringUTF8(aPluginKey, kPluginsNameKey, getter_Copies(name));
  PRUint8 * name;
  PRUint32 length;
  aRegistry->GetBytesUTF8(aPluginKey, kPluginsNameKey, &length, &name);

  nsXPIDLCString description;
  aRegistry->GetStringUTF8(aPluginKey, kPluginsDescKey, getter_Copies(description));
  PRUint8 * description;
  aRegistry->GetBytesUTF8(aPluginKey, kPluginsDescKey, &length, &description);

  nsXPIDLCString filename;
  nsXPIDLCString fullpath;
@@ -4808,7 +4818,11 @@ LoadXPCOMPlugin(nsIRegistry* aRegistry,
    }

    aRegistry->GetStringUTF8(key, kPluginsMimeTypeKey, &mimetypes[count]);
    aRegistry->GetStringUTF8(key, kPluginsMimeDescKey, &mimedescriptions[count]);

    PRUint8 * md;
    aRegistry->GetBytesUTF8(key, kPluginsMimeDescKey, &length, &md);
    mimedescriptions[count] = NS_REINTERPRET_CAST(char *, md);

    aRegistry->GetStringUTF8(key, kPluginsMimeExtKey, &extensions[count]);
    ++count;
  }
@@ -4816,8 +4830,8 @@ LoadXPCOMPlugin(nsIRegistry* aRegistry,
  if (NS_SUCCEEDED(rv)) {
    // All done! Create the new nsPluginTag info and send it back.
    nsPluginTag* tag
      = new nsPluginTag(name.get(),
                        description.get(),
      = new nsPluginTag(NS_REINTERPRET_CAST(const char *, name),
                        NS_REINTERPRET_CAST(const char *, description),
                        aFilename ? aFilename : filename.get(),
                        fullpath.get(),
                        (const char* const*)mimetypes,
@@ -4849,17 +4863,23 @@ static nsresult
AddPluginInfoToRegistry(nsIRegistry* registry, nsRegistryKey top,
                        nsPluginTag *tag, const char *keyname)
{
  NS_ENSURE_ARG_POINTER(tag);
  nsRegistryKey pluginKey;
  nsresult rv = registry->AddSubtree(top, keyname, &pluginKey);
  if (NS_FAILED(rv)) return rv;

  // Add filename, name and description
  registry->SetStringUTF8(pluginKey, kPluginsFilenameKey, tag->mFileName);
    if (tag->mFullPath) {
  if (tag->mFullPath)
    registry->SetStringUTF8(pluginKey, kPluginsFullpathKey, tag->mFullPath);
    }
    registry->SetStringUTF8(pluginKey, kPluginsNameKey, tag->mName);
    registry->SetStringUTF8(pluginKey, kPluginsDescKey, tag->mDescription);

  // we use SetBytes instead of SetString to address special character issue, see Mozilla bug 108246
  if(tag->mName)
    registry->SetBytesUTF8(pluginKey, kPluginsNameKey, nsCRT::strlen(tag->mName) + 1, (PRUint8 *)tag->mName);
  
  if(tag->mDescription)
    registry->SetBytesUTF8(pluginKey, kPluginsDescKey, nsCRT::strlen(tag->mDescription) + 1, (PRUint8 *)tag->mDescription);

  registry->SetLongLong(pluginKey, kPluginsModTimeKey, &(tag->mLastModifiedTime));
  registry->SetInt(pluginKey, kPluginsCanUnload, tag->mCanUnloadLibrary);

@@ -4872,12 +4892,17 @@ AddPluginInfoToRegistry(nsIRegistry* registry, nsRegistryKey top,
    if (NS_FAILED(rv))
      break;
    registry->SetStringUTF8(mimetypeKey, kPluginsMimeTypeKey, tag->mMimeTypeArray[i]);
      registry->SetStringUTF8(mimetypeKey, kPluginsMimeDescKey, tag->mMimeDescriptionArray[i]);

    if(tag->mMimeDescriptionArray[i])
      registry->SetBytesUTF8(mimetypeKey, kPluginsMimeDescKey, 
                             nsCRT::strlen(tag->mMimeDescriptionArray[i]) + 1, 
                             (PRUint8 *)tag->mMimeDescriptionArray[i]);

    registry->SetStringUTF8(mimetypeKey, kPluginsMimeExtKey, tag->mExtensionsArray[i]);
  }
    if (NS_FAILED(rv)) {
  if (NS_FAILED(rv))
    rv = registry->RemoveSubtree(top, keyname);
    }

  return rv;
}