Skip to content

Commit a60763c

Browse files
committed
tokeninfo: fix null pointer crash in tokenDelete function
The tokenDelete() function in main/tokeninfo.c was being called with NULL pointers from the R6 parser error handling code, causing segmentation faults. The R6 parser in parsers/r-r6class.c had a comment stating "tokenDelete accepts NULL" but the function did not actually handle NULL pointers safely. This occurred when parsing malformed R6 syntax such as: - R6::SomethingElse() (wrong function after R6 namespace) - R6:: (incomplete namespace reference) - R6::R6Clas() (typo in R6Class) The fix ensures ctags handles malformed R6 syntax gracefully by falling back to parsing assignments as regular global variables instead of crashing. Fixes segmentation fault when processing certain R6Class syntax patterns. Signed-off-by: Bernát Gábor <[email protected]>
1 parent ead1d93 commit a60763c

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--sort=no
2+
--fields=+ilaKSe{extras}
3+
--extras=-p
4+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TestCase1 input.r /^TestCase1 <- R6::SomethingElse("TestCase1")$/;" globalVar language:R end:6
2+
TestCase2 input.r /^TestCase2 <- R6::$/;" globalVar language:R end:10
3+
TestCase3 input.r /^TestCase3 <- R6::R6Clas("TestCase3")$/;" globalVar language:R end:12
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Test case for R6 parser null pointer regression
2+
# This triggers the error path in r6ReadRightSideSymbol that was causing
3+
# tokenDelete to be called with NULL pointers
4+
5+
# Case 1: R6:: followed by something other than R6Class
6+
TestCase1 <- R6::SomethingElse("TestCase1")
7+
8+
# Case 2: Incomplete R6 namespace reference
9+
TestCase2 <- R6::
10+
11+
# Case 3: R6 followed by :: but with syntax error
12+
TestCase3 <- R6::R6Clas("TestCase3")
13+

main/tokeninfo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void flashTokenBacklog (struct tokenInfoClass *klass)
9191

9292
void tokenDelete (tokenInfo *token)
9393
{
94-
objPoolPut (token->klass->pool, token);
94+
if (token != NULL)
95+
objPoolPut (token->klass->pool, token);
9596
}
9697

9798

0 commit comments

Comments
 (0)