Skip to content

Commit d8fa0d6

Browse files
authored
Merge pull request #3159 from masatake/vhdl-fix-crash
VHDL: avoid dereferencing NULL as a tagEntryInfo
2 parents 43448e8 + 6aa3f13 commit d8fa0d6

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This includes input files that crashed ctags processes.
2+
The validity of the input files is not considered well.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package body

parsers/vhdl.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* This module contains functions for generating tags for VHDL files.
88
*
99
* References:
10+
* https://rti.etf.bg.ac.rs/rti/ri5rvl/tutorial/TUTORIAL/IEEE/HTML/1076_TOC.HTM
11+
* https://tams.informatik.uni-hamburg.de/vhdl/tools/grammar/vhdl93-bnf.html
1012
* http://www.vhdl.renerta.com/mobile/index.html
1113
* https://www.hdlworks.com/hdl_corner/vhdl_ref/
1214
* https://www.ics.uci.edu/~jmoorkan/vhdlref/Synario%20VHDL%20Manual.pdf
@@ -348,9 +350,8 @@ static bool isIdentifierMatch (const tokenInfo * const token,
348350
const char *name)
349351
{
350352
return (bool) (isType (token, TOKEN_IDENTIFIER) &&
351-
strcasecmp (vStringValue (token->string), name) == 0);
352-
/* XXX this is copy/paste from eiffel.c and slightly modified */
353-
/* shouldn't we use strNcasecmp ? */
353+
strncasecmp (vStringValue (token->string), name,
354+
vStringLength (token->string)) == 0);
354355
}
355356

356357
static bool isSemicolonOrKeywordOrIdent (const tokenInfo * const token,
@@ -589,16 +590,18 @@ static void parseTillEnd (tokenInfo * const token, int parent, const int end_key
589590
{
590591
bool ended = false;
591592
tagEntryInfo *e = getEntryInCorkQueue (parent);
592-
const char *end_id = e->name;
593+
/* If e is NULL, the input may be broken as VHDL code
594+
* or unsupported syntax in this parser. */
593595

594596
do
595597
{
596598
readToken (token);
597599
if (isKeyword (token, KEYWORD_END))
598600
{
599601
readToken (token);
600-
ended = isSemicolonOrKeywordOrIdent (token,
601-
end_keyword, end_id);
602+
if (e)
603+
ended = isSemicolonOrKeywordOrIdent (token,
604+
end_keyword, e->name);
602605
if (!isType (token, TOKEN_SEMICOLON))
603606
skipToCharacterInInputFile (';');
604607
if (ended)

0 commit comments

Comments
 (0)