qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject qpid-proton git commit: fixed memory corruption issues from improper use of set/getValue
Date Mon, 02 Feb 2015 12:41:51 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 0c855d911 -> 571cd4196


fixed memory corruption issues from improper use of set/getValue


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/571cd419
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/571cd419
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/571cd419

Branch: refs/heads/master
Commit: 571cd4196384c520b75ee4ee657f4c9b8fd25234
Parents: 0c855d9
Author: Rafael Schloming <rhs@alum.mit.edu>
Authored: Mon Feb 2 07:41:35 2015 -0500
Committer: Rafael Schloming <rhs@alum.mit.edu>
Committed: Mon Feb 2 07:41:35 2015 -0500

----------------------------------------------------------------------
 proton-c/bindings/javascript/data.js    | 13 +++++++++----
 proton-c/bindings/javascript/message.js | 12 +++++++++---
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/571cd419/proton-c/bindings/javascript/data.js
----------------------------------------------------------------------
diff --git a/proton-c/bindings/javascript/data.js b/proton-c/bindings/javascript/data.js
index 018c5fb..061d2bd 100644
--- a/proton-c/bindings/javascript/data.js
+++ b/proton-c/bindings/javascript/data.js
@@ -1239,19 +1239,24 @@ _Data_['copy'] = function() {
  * @returns {string} a formatted string representation of the encoded Data.
  */
 _Data_['format'] = function() {
+    var sp = Runtime.stackSave();
+    var sizeptr = allocate(4, 'i32', ALLOC_STACK);
+
     var size = 1024; // Pass by reference variable - need to use setValue to initialise it.
     while (true) {
-        setValue(size, size, 'i32'); // Set pass by reference variable.
+        setValue(sizeptr, size, 'i32'); // Set pass by reference variable.
         var bytes = _malloc(size);   // Allocate storage from emscripten heap.
-        var err = _pn_data_format(this._data, bytes, size);
-        var size = getValue(size, 'i32'); // Dereference the real size value;
+        var err = _pn_data_format(this._data, bytes, sizeptr);
+        var size = getValue(sizeptr, 'i32'); // Dereference the real size value;
 
         if (err === Module['Error']['OVERFLOW']) {
             _free(bytes);
             size *= 2;
         } else {
-            var string = Pointer_stringify(bytes);
+            var string = Pointer_stringify(bytes, size);
             _free(bytes);
+            // Tidy up the memory that we allocated on emscripten's stack.
+            Runtime.stackRestore(sp);
             this._check(err)
             return string;
         }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/571cd419/proton-c/bindings/javascript/message.js
----------------------------------------------------------------------
diff --git a/proton-c/bindings/javascript/message.js b/proton-c/bindings/javascript/message.js
index cbdba55..bcab604 100644
--- a/proton-c/bindings/javascript/message.js
+++ b/proton-c/bindings/javascript/message.js
@@ -811,19 +811,25 @@ _Message_['setReplyToGroupID'] = function(id) {
  */
 _Message_['encode'] = function() {
     this._preEncode();
+    var sp = Runtime.stackSave();
+    var sizeptr = allocate(4, 'i32', ALLOC_STACK);
     var size = 1024;
     while (true) {
-        setValue(size, size, 'i32'); // Set pass by reference variable.
+        setValue(sizeptr, size, 'i32'); // Set pass by reference variable.
         var bytes = _malloc(size);   // Allocate storage from emscripten heap.
-        var err = _pn_message_encode(this._message, bytes, size);
-        var size = getValue(size, 'i32'); // Dereference the real size value;
+        var err = _pn_message_encode(this._message, bytes, sizeptr);
+        var size = getValue(sizeptr, 'i32'); // Dereference the real size value;
 
         if (err === Module['Error']['OVERFLOW']) {
             _free(bytes);
             size *= 2;
         } else if (err >= 0) {
+            // Tidy up the memory that we allocated on emscripten's stack.
+            Runtime.stackRestore(sp);
             return new Data['Binary'](size, bytes);
         } else {
+            // Tidy up the memory that we allocated on emscripten's stack.
+            Runtime.stackRestore(sp);
             _free(bytes);
             this._check(err);
             return;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message