aboutsummaryrefslogtreecommitdiff
path: root/javascript/olm_outbound_group_session.js
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-04-08 15:54:02 -0400
committerHubert Chathi <hubert@uhoreg.ca>2019-04-08 15:54:02 -0400
commitebc156e7c272e08e375c3e704651b179541e078b (patch)
treeca421f9d429f009e1c939bf96314fd4764ae241b /javascript/olm_outbound_group_session.js
parent071029c20174307de28ca20232196f83fcc37763 (diff)
re-add null termination in javascript
because older versions of emscripten don't support the length argument to UTF8ToString.
Diffstat (limited to 'javascript/olm_outbound_group_session.js')
-rw-r--r--javascript/olm_outbound_group_session.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/javascript/olm_outbound_group_session.js b/javascript/olm_outbound_group_session.js
index e4427cc..e4852c1 100644
--- a/javascript/olm_outbound_group_session.js
+++ b/javascript/olm_outbound_group_session.js
@@ -28,7 +28,7 @@ OutboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
Module['_olm_pickle_outbound_group_session_length']
)(this.ptr);
var key_buffer = stack(key_array);
- var pickle_buffer = stack(pickle_length);
+ var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
try {
outbound_group_session_method(Module['_olm_pickle_outbound_group_session'])(
this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
@@ -86,13 +86,20 @@ OutboundGroupSession.prototype['encrypt'] = function(plaintext) {
plaintext_buffer = malloc(plaintext_length + 1);
stringToUTF8(plaintext, plaintext_buffer, plaintext_length + 1);
- message_buffer = malloc(message_length);
+ message_buffer = malloc(message_length + NULL_BYTE_PADDING_LENGTH);
outbound_group_session_method(Module['_olm_group_encrypt'])(
this.ptr,
plaintext_buffer, plaintext_length,
message_buffer, message_length
);
+ // UTF8ToString requires a null-terminated argument, so add the
+ // null terminator.
+ setValue(
+ message_buffer+message_length,
+ 0, "i8"
+ );
+
return UTF8ToString(message_buffer, message_length);
} finally {
if (plaintext_buffer !== undefined) {
@@ -110,7 +117,7 @@ OutboundGroupSession.prototype['session_id'] = restore_stack(function() {
var length = outbound_group_session_method(
Module['_olm_outbound_group_session_id_length']
)(this.ptr);
- var session_id = stack(length);
+ var session_id = stack(length + NULL_BYTE_PADDING_LENGTH);
outbound_group_session_method(Module['_olm_outbound_group_session_id'])(
this.ptr, session_id, length
);
@@ -121,7 +128,7 @@ OutboundGroupSession.prototype['session_key'] = restore_stack(function() {
var key_length = outbound_group_session_method(
Module['_olm_outbound_group_session_key_length']
)(this.ptr);
- var key = stack(key_length);
+ var key = stack(key_length + NULL_BYTE_PADDING_LENGTH);
outbound_group_session_method(Module['_olm_outbound_group_session_key'])(
this.ptr, key, key_length
);