]> source.dussan.org Git - rspamd.git/commitdiff
More fixes to regexp module.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Mar 2015 00:25:39 +0000 (00:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Mar 2015 00:25:39 +0000 (00:25 +0000)
src/libutil/regexp.c
src/lua/lua_regexp.c

index 9a57ed380abc75ec74ff3f51ee23291dec342f59..3f93051f6b3bef5b18e61dea8d9e5b2ee0ba66fb 100644 (file)
@@ -283,11 +283,11 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
 {
        pcre *r;
        pcre_extra *ext;
-#ifdef HAVE_PCRE_JIT
+#if defined(HAVE_PCRE_JIT) && (PCRE_MAJOR == 8 && PCRE_MINOR >= 32)
        pcre_jit_stack *st;
 #endif
        const gchar *mt;
-       gsize remain;
+       gsize remain = 0;
        gint rc, match_flags = 0, ovec[10];
 
        g_assert (re != NULL);
@@ -295,19 +295,26 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
 
        if (end != NULL && *end != NULL) {
                /* Incremental search */
-               mt = (*end) + 1;
-               remain = len - (mt - text);
+               mt = (*end);
+
+               if ((gint)len > (mt - text)) {
+                       remain = len - (mt - text);
+               }
        }
        else {
                mt = text;
                remain = len;
        }
 
+       if (remain == 0) {
+               return FALSE;
+       }
+
        match_flags = PCRE_NEWLINE_ANYCRLF;
        if ((re->flags & RSPAMD_REGEXP_FLAG_RAW) || raw) {
                r = re->raw_re;
                ext = re->raw_extra;
-#ifdef HAVE_PCRE_JIT
+#if defined(HAVE_PCRE_JIT) && (PCRE_MAJOR == 8 && PCRE_MINOR >= 32)
                st = re->raw_jstack;
 #endif
        }
@@ -315,7 +322,7 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
                match_flags |= PCRE_NO_UTF8_CHECK;
                r = re->re;
                ext = re->extra;
-#ifdef HAVE_PCRE_JIT
+#if defined(HAVE_PCRE_JIT) && (PCRE_MAJOR == 8 && PCRE_MINOR >= 32)
                st = re->jstack;
 #endif
        }
@@ -330,8 +337,13 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len,
 
        if (!(re->flags & RSPAMD_REGEXP_FLAG_NOOPT)) {
 #ifdef HAVE_PCRE_JIT
+# if (PCRE_MAJOR == 8 && PCRE_MINOR >= 32)
                rc = pcre_jit_exec (r, ext, mt, remain, 0, match_flags, ovec,
                                G_N_ELEMENTS (ovec), st);
+# else
+               rc = pcre_exec (r, ext, mt, remain, 0, match_flags, ovec,
+                                               G_N_ELEMENTS (ovec));
+#endif
 #else
                rc = pcre_exec (r, ext, mt, remain, 0, match_flags, ovec,
                                G_N_ELEMENTS (ovec));
index 64312be7000cfc7ecd702467cef74e0958209101..d363ee4a67bb47ebb507608a4b9b1a80b9adf363 100644 (file)
@@ -141,10 +141,13 @@ lua_regexp_get_cached (lua_State *L)
 {
        struct rspamd_lua_regexp *new, **pnew;
        const gchar *line;
+       rspamd_regexp_t *re;
 
        line = luaL_checkstring (L, 1);
-       new = rspamd_regexp_cache_query (NULL, line, NULL);
-       if (new) {
+       re = rspamd_regexp_cache_query (NULL, line, NULL);
+       if (re) {
+               new = g_slice_alloc (sizeof (struct rspamd_lua_regexp));
+               new->re = re;
                pnew = lua_newuserdata (L, sizeof (struct rspamd_lua_regexp *));
                rspamd_lua_setclass (L, "rspamd{regexp}", -1);
                *pnew = new;
@@ -176,11 +179,15 @@ lua_regexp_create_cached (lua_State *L)
 {
        const gchar *line;
        struct rspamd_lua_regexp *new, **pnew;
+       rspamd_regexp_t *re;
 
        line = luaL_checkstring (L, 1);
-       new = rspamd_regexp_cache_query (NULL, line, NULL);
-       if (new) {
+       re = rspamd_regexp_cache_query (NULL, line, NULL);
+       if (re) {
+               new = g_slice_alloc (sizeof (struct rspamd_lua_regexp));
+               new->re = re;
                pnew = lua_newuserdata (L, sizeof (struct rspamd_lua_regexp *));
+
                rspamd_lua_setclass (L, "rspamd{regexp}", -1);
                *pnew = new;
        }