Bug 1373579: Part 2 - Check fallible BufferList allocation in setCloneBuffer. r?billm draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 16 Jun 2017 16:36:20 -0700
changeset 595924 c47798937b91ec7e65f1b1bd7e0bd341fb95ee77
parent 595923 ba55cf32c7cc93a9c37b96df2f1f66585b387865
child 595925 0504a961e5826e65adafc0e37c1e9fbd62630038
push id64471
push usermaglione.k@gmail.com
push dateFri, 16 Jun 2017 23:41:45 +0000
reviewersbillm
bugs1373579
milestone56.0a1
Bug 1373579: Part 2 - Check fallible BufferList allocation in setCloneBuffer. r?billm MozReview-Commit-ID: Jn7iAVAT1v5
js/src/builtin/TestingFunctions.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -2373,16 +2373,18 @@ class CloneBufferObject : public NativeO
         obj->discard();
 
         char* str = JS_EncodeString(cx, args[0].toString());
         if (!str)
             return false;
         size_t nbytes = JS_GetStringLength(args[0].toString());
         MOZ_ASSERT(nbytes % sizeof(uint64_t) == 0);
         auto buf = js::MakeUnique<JSStructuredCloneData>(nbytes, nbytes, nbytes);
+        if (buf->Size() < nbytes)
+            return false;
         js_memcpy(buf->Start(), str, nbytes);
         JS_free(cx, str);
         obj->setData(buf.release());
 
         args.rval().setUndefined();
         return true;
     }