From 0b4a18a067306b83d234a428a423623993efd39a Mon Sep 17 00:00:00 2001 From: Lech Lorens Date: Sun, 25 Apr 2010 12:30:03 +0200 Subject: [PATCH] feat/tagfunc: preventing too deep recursion in calls to 'tagfunc'. 5 levels of recursion are allowed. --- src/tag.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/tag.c b/src/tag.c index 0e0e20e1..52da9703 100644 --- a/src/tag.c +++ b/src/tag.c @@ -1251,24 +1251,29 @@ find_tfu_tags(char_u *pat, garray_T *ga, int *match_count) listitem_T *item, *item2; int ntags = 0; const int nfieds_required = 3; + int result = FAIL; - /* FIXME:2010-04-24:llorens: check if recursive! */ + static int call_level = 0; + + /* Prevent endless loop: */ + ++call_level; + if (call_level > 5) + goto done; if (*curbuf->b_p_tfu == NUL) - return FAIL; + goto done; pos = curwin->w_cursor; taglist = call_func_retlist(curbuf->b_p_tfu, 1, &pat, FALSE); curwin->w_cursor = pos; /* restore the cursor position */ if (taglist == NULL) - return FAIL; + goto done; for (item = taglist->lv_first; item != NULL; item = item->li_next) { struct match_found *mfp; int len; - /* TODO:2010-04-24:llorens: process the list... */ if (item->li_tv.v_type != VAR_LIST) { /* FIXME:2010-04-24:llorens: ... */ @@ -1329,6 +1334,7 @@ find_tfu_tags(char_u *pat, garray_T *ga, int *match_count) { ((struct match_found **)(ga->ga_data)) [ga->ga_len++] = mfp; ++ntags; + result = OK; } else vim_free(mfp); @@ -1336,8 +1342,10 @@ find_tfu_tags(char_u *pat, garray_T *ga, int *match_count) } list_free(taglist, TRUE); +done: + --call_level; *match_count = ntags; - return ntags == 0? FAIL: OK; + return result; } /* -- 2.11.4.GIT