[PATCH spice-xpi 2/2] ScriptablePluginObject: fix issues in SetProperty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]