Commit 118acb80 authored by kicer's avatar kicer Committed by Philip Gladstone
Browse files

Fix crypto.mask() to encode with correct mask (#1677) (#1678)

Thank you.
parent 1452fbfd
...@@ -124,13 +124,19 @@ static int crypto_mask( lua_State* L ) ...@@ -124,13 +124,19 @@ static int crypto_mask( lua_State* L )
int len, mask_len; int len, mask_len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
const char* mask = luaL_checklstring(L, 2, &mask_len); const char* mask = luaL_checklstring(L, 2, &mask_len);
if(mask_len <= 0)
return luaL_error(L, "invalid argument: mask");
int i; int i;
char* copy = (char*)c_malloc(len); char* copy = (char*)c_malloc(len);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
copy[i] = msg[i] ^ mask[i % 4]; copy[i] = msg[i] ^ mask[i % mask_len];
} }
lua_pushlstring(L, copy, len); lua_pushlstring(L, copy, len);
c_free(copy); c_free(copy);
return 1; return 1;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment