Skip to content

Commit

Permalink
readtags: handle non-terminated input pattern
Browse files Browse the repository at this point in the history
If an input pattern is not terminated with / (or ?), readtags crashed.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 22, 2018
1 parent bf8aa43 commit 9275da8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions Tmain/readtags-broken-input.d/exit-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
21 changes: 21 additions & 0 deletions Tmain/readtags-broken-input.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Copyright: 2018 Masatake YAMATO
# License: GPL-2

READTAGS=$3
#V="valgrind --leak-check=full --track-origins=yes -v"
V=

. ../utils.sh

if ! [ -x "${READTAGS}" ]; then
skip "no readtags"
fi

for i in 1 2 3 4 5 6; do
${V} ${READTAGS} -t ./target.tags - greet${i} > /dev/null || exit 1
done

${READTAGS} -t ./target.tags - greetA
${READTAGS} -t ./target.tags - greetB
Empty file.
2 changes: 2 additions & 0 deletions Tmain/readtags-broken-input.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
greetA input.java /^ public void greet (String word) {$/
greetB input.java ?^ public void greet (String word) {$?
8 changes: 8 additions & 0 deletions Tmain/readtags-broken-input.d/target.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
greet1 input.java /^ public void greet (String word) {$;" m line:9 method:input.hello.anonXXX
greetA input.java /^ public void greet (String word) {$/;" m line:9 method:input.hello.anonXXX
greet2 input.java k:v
greet3 input.java
greet4 input.java
greet5
greetB input.java ?^ public void greet (String word) {$?;" m line:9 method:input.hello.anonXXX
greet6 input.java ?^ public void greet (String word) {$;" m line:9 method:input.hello.anonXXX
12 changes: 8 additions & 4 deletions read/readtags.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,14 @@ static void parseTagLine (tagFile *file, tagEntry *const entry)
{
/* invalid pattern */
}
fieldsPresent = (strncmp (p, ";\"", 2) == 0);
*p = '\0';
if (fieldsPresent)
parseExtensionFields (file, entry, p + 2);

if (p)
{
fieldsPresent = (strncmp (p, ";\"", 2) == 0);
*p = '\0';
if (fieldsPresent)
parseExtensionFields (file, entry, p + 2);
}
}
}
if (entry->fields.count > 0)
Expand Down

0 comments on commit 9275da8

Please sign in to comment.