browser-plugin: Prevent a copy when checking for valid extension UUIDs

Instead of using g_strndup to copy the NPString that gets passed to us
by the plugin host, just use the equally-as-good NPString directly. We
still need to copy the string when passing it over DBus, as there's no
easy way to construct a string GVariant from a length-prefixed string.

https://bugzilla.gnome.org/show_bug.cgi?id=679099
This commit is contained in:
Jasper St. Pierre 2012-06-15 17:46:33 -04:00
parent 48b83f1ffd
commit 67689f1a6d

View File

@ -399,13 +399,13 @@ plugin_object_has_method (NPObject *npobj,
} }
static inline gboolean static inline gboolean
uuid_is_valid (const gchar *uuid) uuid_is_valid (NPString string)
{ {
gsize i; gsize i;
for (i = 0; uuid[i]; i ++) for (i = 0; i < string.UTF8Length; i++)
{ {
gchar c = uuid[i]; gchar c = string.UTF8Characters[i];
if (c < 32 || c >= 127) if (c < 32 || c >= 127)
return FALSE; return FALSE;
@ -499,17 +499,15 @@ plugin_enable_extension (PluginObject *obj,
gboolean enabled) gboolean enabled)
{ {
gboolean ret; gboolean ret;
gchar *uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); gchar *uuid_str;
gsize length; gsize length;
gchar **uuids; gchar **uuids;
const gchar **new_uuids; const gchar **new_uuids;
if (!uuid_is_valid (uuid_str)) if (!uuid_is_valid (uuid))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
uuids = g_settings_get_strv (obj->settings, ENABLED_EXTENSIONS_KEY); uuids = g_settings_get_strv (obj->settings, ENABLED_EXTENSIONS_KEY);
length = g_strv_length (uuids); length = g_strv_length (uuids);
@ -551,13 +549,12 @@ static gboolean
plugin_install_extension (PluginObject *obj, plugin_install_extension (PluginObject *obj,
NPString uuid) NPString uuid)
{ {
gchar *uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); gchar *uuid_str;
if (!uuid_is_valid (uuid_str)) if (!uuid_is_valid (uuid))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
g_dbus_proxy_call (obj->proxy, g_dbus_proxy_call (obj->proxy,
"InstallRemoteExtension", "InstallRemoteExtension",
@ -582,12 +579,10 @@ plugin_uninstall_extension (PluginObject *obj,
GVariant *res; GVariant *res;
gchar *uuid_str; gchar *uuid_str;
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); if (!uuid_is_valid (uuid))
if (!uuid_is_valid (uuid_str))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
res = g_dbus_proxy_call_sync (obj->proxy, res = g_dbus_proxy_call_sync (obj->proxy,
"UninstallExtension", "UninstallExtension",
@ -619,12 +614,10 @@ plugin_get_info (PluginObject *obj,
GVariant *res; GVariant *res;
gchar *uuid_str; gchar *uuid_str;
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); if (!uuid_is_valid (uuid))
if (!uuid_is_valid (uuid_str))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
res = g_dbus_proxy_call_sync (obj->proxy, res = g_dbus_proxy_call_sync (obj->proxy,
"GetExtensionInfo", "GetExtensionInfo",
@ -655,12 +648,10 @@ plugin_get_errors (PluginObject *obj,
GVariant *res; GVariant *res;
gchar *uuid_str; gchar *uuid_str;
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); if (!uuid_is_valid (uuid))
if (!uuid_is_valid (uuid_str))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
res = g_dbus_proxy_call_sync (obj->proxy, res = g_dbus_proxy_call_sync (obj->proxy,
"GetExtensionErrors", "GetExtensionErrors",
@ -689,12 +680,10 @@ plugin_launch_extension_prefs (PluginObject *obj,
{ {
gchar *uuid_str; gchar *uuid_str;
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length); if (!uuid_is_valid (uuid))
if (!uuid_is_valid (uuid_str))
{
g_free (uuid_str);
return FALSE; return FALSE;
}
uuid_str = g_strndup (uuid.UTF8Characters, uuid.UTF8Length);
g_dbus_proxy_call (obj->proxy, g_dbus_proxy_call (obj->proxy,
"LaunchExtensionPrefs", "LaunchExtensionPrefs",