aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-01-18 16:48:29 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-01-18 16:48:29 +0000
commitafa975523e60d36be65d5b79d650a1c98e0a3b0d (patch)
tree10039476df23e99055864578ac69458088c82024 /src/lua/lua_util.c
parent3203d0f4422fdab18a03abf7fc713c562f15f70e (diff)
downloadrspamd-afa975523e60d36be65d5b79d650a1c98e0a3b0d.tar.gz
rspamd-afa975523e60d36be65d5b79d650a1c98e0a3b0d.zip
[Minor] Core: Add lua utility to find some obscured unicode symbols
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r--src/lua/lua_util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 81b44bd28..94554faa1 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -400,6 +400,13 @@ LUA_FUNCTION_DEF (util, is_utf_spoofed);
LUA_FUNCTION_DEF (util, is_valid_utf8);
/***
+ * @function util.has_obscured_utf(str)
+ * Returns true if a string has obscure UTF symbols (zero width spaces, order marks), ignores invalid utf characters
+ * @return {boolean} true if a has obscured utf characters
+ */
+LUA_FUNCTION_DEF (util, has_obscured_utf);
+
+/***
* @function util.readline([prompt])
* Returns string read from stdin with history and editing support
* @return {string} string read from the input (with line endings stripped)
@@ -609,6 +616,7 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, caseless_hash_fast),
LUA_INTERFACE_DEF (util, is_utf_spoofed),
LUA_INTERFACE_DEF (util, is_valid_utf8),
+ LUA_INTERFACE_DEF (util, has_obscured_utf),
LUA_INTERFACE_DEF (util, readline),
LUA_INTERFACE_DEF (util, readpassphrase),
LUA_INTERFACE_DEF (util, file_exists),
@@ -2610,6 +2618,36 @@ lua_util_is_valid_utf8 (lua_State *L)
}
static gint
+lua_util_has_obscured_utf (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ const gchar *str;
+ gsize len;
+ gint32 i = 0;
+ UChar32 uc;
+
+ str = lua_tolstring (L, 1, &len);
+
+ while (i < len) {
+ U8_NEXT (str, i, len, uc);
+
+ if (uc > 0) {
+ if (IS_OBSCURED_CHAR (uc)) {
+ lua_pushboolean (L, true);
+ lua_pushnumber (L, uc); /* Character */
+ lua_pushnumber (L, i); /* Offset */
+
+ return 3;
+ }
+ }
+ }
+
+ lua_pushboolean (L, false);
+
+ return 1;
+}
+
+static gint
lua_util_readline (lua_State *L)
{
LUA_TRACE_POINT;