Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle variety scenarios that a mtable parser enters an infinite loop #1719

Merged

Conversation

masatake
Copy link
Member

( I have to do the same overhauling the mline meta parser.)

By nature, a mtable regex parser can enter an infinite loop.  This change
is for avoiding entering infinite loop resulted from a simple
programming mistake.

Following conditions for entering infinite loop are satisfied:
+ matching the pattern succeeds,
+ the next table is not given, and
+ The input file pos doesn't advance.

Following parser for an empty file satisfies the condition:

    --langdef=FOO
    --_tabledef-FOO=main
    --kinddef-FOO=e,eof,the end of file
    --_mtable-regex-FOO=main//eof/e/

This commit advances the input pos forcefully when detecting the
conditions are met.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
The combination of an input file and an empty regex pattern (//)
caused an error with the following message:

       ctags: could not read tag line from ./input.foo at line 1

This commit accepts the combination.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
When ctags reaches the end of the input file, ctags runs mtable and
mline parsers.

Reaching the end can happens twice. As the result ctags may run a
mtable (or mline) parser twice for the same input file. This is a bug.

See createTagsWithFallback1.  It calls createTagsForFile. During
running this function, reaching the end can happens once.

After calling createTagsForFile, createTagsWithFallback1 calls
readLineFromInputFile in a loop. Reaching the end can happens once
again.

To avoid the bug, we need a mechanism to limit running the parsers for
the same input only once.

This commit uses File.allLines as a flag.  ctags verifies
File.allLines is not NULL before running the parsers.  If it is NULL,
skip the running.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…empty pattern.

This case is for tests the following commits:

* mtable-lregex: avoid entering infinite loop when reaching EOF
* mtable-lregex: accept empty output pattern in tags file
* mtable|mline-lregex avoid running a parser twice for the same input file

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
By nature, a mtable regex parser can enter an infinite loop.
This change is for avoiding entering infinite loop resulted from a
simple programming mistake.

This commit limits the depth of stack where tables are pushed.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…n so long time

By nature, a mtable regex parser can enter an infinite loop.
This change is for avoiding entering infinite loop resulted from a
simple programming mistake.

When a parser doesn't consume an input stream so long time, we can
assume it enters an infinite loop. In such cases, ctags stops running
the parser for the input with warning.

This commit deals with the following case:

A. a parser doesn't advance the input position repeatedly, and
B. its table stack doesn't grow so deep but it switches the tables.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@coveralls
Copy link

coveralls commented Mar 28, 2018

Coverage Status

Coverage increased (+0.02%) to 84.765% when pulling a33dec3 on masatake:refine-mtable-regex-meta-parser into 41fa40d on universal-ctags:master.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake masatake force-pushed the refine-mtable-regex-meta-parser branch 2 times, most recently from d1034d2 to 2bfce46 Compare March 31, 2018 13:15
Pattern matching should be done with sliding the input position.  The
advance of the sliding being zero means a parser entering an infinite
loop.

With this commit, the mline lregex meta parser checks the advance
everytime matching is successful; if the advance is zero, the meta
parser warns it.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake masatake force-pushed the refine-mtable-regex-meta-parser branch from 2bfce46 to a33dec3 Compare March 31, 2018 14:39
@masatake masatake merged commit e0d8b8d into universal-ctags:master Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants