From 0e85c23ee12fa524ac9056ee0275fd3c4b15c612 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 30 Jun 2015 18:26:48 +0100 Subject: Fix issues with capturing patterns --- src/libutil/regexp.c | 6 +++--- src/lua/lua_regexp.c | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index 529895b7b..da9884ec1 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -335,7 +335,7 @@ fin: rspamd_regexp_generate_id (pattern, flags, res->id); /* Check number of captures */ - if (pcre_fullinfo (res->re, res->extra, PCRE_INFO_CAPTURECOUNT, + if (pcre_fullinfo (res->raw_re, res->extra, PCRE_INFO_CAPTURECOUNT, &ncaptures) == 0) { res->ncaptures = ncaptures; } @@ -445,9 +445,9 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len, g_assert (g_array_get_element_size (captures) == sizeof (struct rspamd_re_capture)); - g_array_set_size (captures, rc - 1); + g_array_set_size (captures, rc); - for (i = 0; i < rc - 1; i ++) { + for (i = 0; i < rc; i ++) { elt = &g_array_index (captures, struct rspamd_re_capture, i); elt->p = mt + ovec[i * 2]; elt->len = (mt + ovec[i * 2 + 1]) - elt->p; diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 60dbc5edc..2f7ea3ea1 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -348,14 +348,12 @@ lua_regexp_search (lua_State *L) if (capture) { lua_newtable (L); - lua_pushlstring (L, start, end - start); - lua_rawseti (L, -2, 1); for (capn = 0; capn < captures->len; capn ++) { cap = &g_array_index (captures, struct rspamd_re_capture, capn); lua_pushlstring (L, cap->p, cap->len); - lua_rawseti (L, -2, capn + 2); + lua_rawseti (L, -2, capn + 1); } lua_rawseti (L, -2, ++i); -- cgit v1.2.3