[Spice-devel] [PATCH spice-xpi 2/2] ScriptablePluginObject: fix issues in SetProperty
Federico Simoncelli
fsimonce at redhat.com
Mon Dec 3 03:04:41 PST 2012
NPVARIANT_TO_STRING doesn't guarantee to have a null-terminated
string, the provided length should be taken in account to assign
the value to other objects. Some browsers (e.g.: chromium) pass
numeric properties as double instead of int32, in order to use
the specified values the support for double has been added.
Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
SpiceXPI/src/plugin/nsScriptablePeer.cpp | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/SpiceXPI/src/plugin/nsScriptablePeer.cpp b/SpiceXPI/src/plugin/nsScriptablePeer.cpp
index caab9b7..622659c 100644
--- a/SpiceXPI/src/plugin/nsScriptablePeer.cpp
+++ b/SpiceXPI/src/plugin/nsScriptablePeer.cpp
@@ -242,12 +242,14 @@ bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant *val
return false;
std::string str;
+ std::stringstream ss;
PRBool boolean = false;
unsigned short val = -1;
if (NPVARIANT_IS_STRING(*value))
{
- str = NPVARIANT_TO_STRING(*value).UTF8Characters;
+ str.assign(NPVARIANT_TO_STRING(*value).UTF8Characters,
+ NPVARIANT_TO_STRING(*value).UTF8Length);
}
else if (NPVARIANT_IS_BOOLEAN(*value))
{
@@ -256,8 +258,12 @@ bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant *val
else if (NPVARIANT_IS_INT32(*value))
{
val = NPVARIANT_TO_INT32(*value);
-
- std::stringstream ss;
+ ss << val;
+ ss >> str;
+ }
+ else if (NPVARIANT_IS_DOUBLE(*value))
+ {
+ val = NPVARIANT_TO_DOUBLE(*value);
ss << val;
ss >> str;
}
--
1.7.1
More information about the Spice-devel
mailing list