aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/wslua/wslua_byte_array.c13
-rw-r--r--test/lua/tvb.lua8
2 files changed, 17 insertions, 4 deletions
diff --git a/epan/wslua/wslua_byte_array.c b/epan/wslua/wslua_byte_array.c
index 96c4650994..5a5455b463 100644
--- a/epan/wslua/wslua_byte_array.c
+++ b/epan/wslua/wslua_byte_array.c
@@ -259,13 +259,20 @@ WSLUA_METHOD ByteArray_base64_decode(lua_State* L) {
ByteArray ba = checkByteArray(L,1);
ByteArray ba2;
gchar *data;
- gsize len;
+ gsize len = ba->len;
+
+ if ((len % 4) != 0) {
+ len += 4 - (len % 4);
+ }
ba2 = g_byte_array_new();
if (ba->len > 1) {
- data = (gchar*)g_malloc(ba->len + 1);
+ data = (gchar*)g_malloc(len + 1);
memcpy(data, ba->data, ba->len);
- data[ba->len] = '\0';
+ if (len > ba->len) {
+ memcpy(data + ba->len, "====", len - ba->len);
+ }
+ data[len] = '\0';
g_base64_decode_inplace(data, &len);
g_byte_array_append(ba2, data, (int)len);
diff --git a/test/lua/tvb.lua b/test/lua/tvb.lua
index 9c9b61e56e..293c97d584 100644
--- a/test/lua/tvb.lua
+++ b/test/lua/tvb.lua
@@ -54,7 +54,7 @@ end
-- number of verifyFields() * (1 + number of fields) +
-- number of verifyResults() * (1 + 2 * number of values)
--
-local taptests = { [FRAME]=4, [OTHER]=335 }
+local taptests = { [FRAME]=4, [OTHER]=337 }
local function getResults()
print("\n-----------------------------\n")
@@ -630,6 +630,12 @@ function test_proto.dissector(tvbuf,pktinfo,root)
verifyResults("add_pfield-bytes", bytes_match_values)
verifyFields("bytes.BYTES", bytes_match_fields)
+ -- extra test of ByteArray
+ local b64padded = ByteArray.new("dGVzdA==", true):base64_decode():raw()
+ local b64unpadded = ByteArray.new("dGVzdA", true):base64_decode():raw()
+ execute ("bytearray_base64_padded", b64padded == "test")
+ execute ("bytearray_base64_unpadded", b64unpadded == "test")
+
----------------------------------------
testing(OTHER, "tree:add_packet_field OID")