Skip to content

Commit 690c36f

Browse files
pablogsalvstinner
authored andcommitted
[3.6] bpo-31852: Fix segfault caused by using the async soft keyword (GH-4122)
1 parent 2702380 commit 690c36f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Lib/test/test_tokenize.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ def test_async(self):
630630
NAME 'async' (1, 0) (1, 5)
631631
OP '=' (1, 6) (1, 7)
632632
NUMBER '1' (1, 8) (1, 9)
633+
""")
634+
635+
self.check_tokenize("async\\", """\
636+
ERRORTOKEN '\\\\' (1, 5) (1, 6)
637+
NAME 'async' (1, 0) (1, 5)
633638
""")
634639

635640
self.check_tokenize("a = (async = 1)", """\
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a segmentation fault caused by a combination of the async soft keyword
2+
and continuation lines.

Parser/tokenizer.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,9 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
15631563
/* The current token is 'async'.
15641564
Look ahead one token.*/
15651565

1566+
int async_def_prev = tok->async_def;
1567+
tok->async_def = 2;
1568+
15661569
struct tok_state ahead_tok;
15671570
char *ahead_tok_start = NULL, *ahead_tok_end = NULL;
15681571
int ahead_tok_kind;
@@ -1581,6 +1584,9 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
15811584
tok->async_def = 1;
15821585
return ASYNC;
15831586
}
1587+
else{
1588+
tok->async_def = async_def_prev;
1589+
}
15841590
}
15851591
}
15861592

@@ -1844,6 +1850,10 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
18441850
/* Line continuation */
18451851
if (c == '\\') {
18461852
c = tok_nextc(tok);
1853+
if (tok->async_def == 2) {
1854+
tok->done = E_SYNTAX;
1855+
return ERRORTOKEN;
1856+
}
18471857
if (c != '\n') {
18481858
tok->done = E_LINECONT;
18491859
tok->cur = tok->inp;

0 commit comments

Comments
 (0)