aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-25 17:52:14 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-25 17:52:14 +0100
commit122b896ba0b85f7d44c7417acd283f6a6ca83e4c (patch)
tree732855c0b73ab2bcc28a74656cdbff1f28f59f68
parentc43c10158c7b711b30cce1f7f8d4e0485acb3dce (diff)
downloadrspamd-122b896ba0b85f7d44c7417acd283f6a6ca83e4c.tar.gz
rspamd-122b896ba0b85f7d44c7417acd283f6a6ca83e4c.zip
Fix ownership issues for zero-copy decode.
-rw-r--r--src/lua/lua_util.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index ad4f80af4..e84b3748b 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -274,7 +274,7 @@ lua_util_decode_base64 (lua_State *L)
struct rspamd_lua_text *t;
const gchar *s = NULL;
gsize inlen, outlen;
- gboolean zero_copy = FALSE;
+ gboolean zero_copy = FALSE, grab_own = FALSE;
gint state = 0;
guint save = 0;
@@ -288,25 +288,29 @@ lua_util_decode_base64 (lua_State *L)
s = t->start;
inlen = t->len;
zero_copy = TRUE;
+ if (t->own) {
+ t->own = FALSE;
+ grab_own = TRUE;
+ }
}
}
if (s != NULL) {
if (zero_copy) {
/* Decode in place */
- outlen = g_base64_decode_step (s, inlen, (gchar *)s, &state, &save);
+ outlen = g_base64_decode_step (s, inlen, (guchar *)s, &state, &save);
t = lua_newuserdata (L, sizeof (*t));
rspamd_lua_setclass (L, "rspamd{text}", -1);
t->start = s;
t->len = outlen;
- t->own = FALSE;
+ t->own = grab_own;
}
else {
t = lua_newuserdata (L, sizeof (*t));
rspamd_lua_setclass (L, "rspamd{text}", -1);
t->len = (inlen / 4) * 3 + 3;
t->start = g_malloc (t->len);
- outlen = g_base64_decode_step (s, inlen, (gchar *)t->start,
+ outlen = g_base64_decode_step (s, inlen, (guchar *)t->start,
&state, &save);
t->len = outlen;
t->own = TRUE;