Bug 777292 - Make sure that the Components.results values are interpreted as unsigned integers; r=bholley
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 20 Sep 2012 09:11:20 -0400
changeset 107738 30ab4e1d48745b68392b493fc98ed97a6df476a1
parent 107737 e21f9042824fe071845302042b37b8b1200f6653
child 107739 bd455398388dc8059aa0509c769b792f9be9e5bd
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbholley
bugs777292
milestone18.0a1
Bug 777292 - Make sure that the Components.results values are interpreted as unsigned integers; r=bholley
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1398,17 +1398,20 @@ nsXPCComponents_Results::NewResolve(nsIX
     JSAutoByteString name;
 
     if (JSID_IS_STRING(id) && name.encode(cx, JSID_TO_STRING(id))) {
         const char* rv_name;
         void* iter = nullptr;
         nsresult rv;
         while (nsXPCException::IterateNSResults(&rv, &rv_name, nullptr, &iter)) {
             if (!strcmp(name.ptr(), rv_name)) {
-                jsval val = JS_NumberValue((double)rv);
+                // The double cast below is required since nsresult is an enum,
+                // and it can be interpreted as a signed integer if we directly
+                // cast to a double.
+                jsval val = JS_NumberValue((double)(uint32_t)rv);
 
                 *objp = obj;
                 if (!JS_DefinePropertyById(cx, obj, id, val,
                                            nullptr, nullptr,
                                            JSPROP_ENUMERATE |
                                            JSPROP_READONLY |
                                            JSPROP_PERMANENT)) {
                     return NS_ERROR_UNEXPECTED;