summaryrefslogtreecommitdiffstats
path: root/Parser/parser.c
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2023-04-27 01:33:31 (GMT)
committerGitHub <noreply@github.com>2023-04-27 01:33:31 (GMT)
commit9169a56fad246364fd3224306e72e0d0725c35aa (patch)
tree2a79d19be8d01fdd08ff5b54080ebfee72ae089d /Parser/parser.c
parent76632b836cf81a95301f4eb1fa43682e8d9ffa67 (diff)
downloadcpython-9169a56fad246364fd3224306e72e0d0725c35aa.zip
cpython-9169a56fad246364fd3224306e72e0d0725c35aa.tar.gz
cpython-9169a56fad246364fd3224306e72e0d0725c35aa.tar.bz2
gh-103656: Transfer f-string buffers to parser to avoid use-after-free (GH-103896)
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Diffstat (limited to 'Parser/parser.c')
-rw-r--r--Parser/parser.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index 7713668..6eb985a 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -738,8 +738,8 @@ static NameDefaultPair* lambda_param_maybe_default_rule(Parser *p);
static arg_ty lambda_param_rule(Parser *p);
static expr_ty fstring_middle_rule(Parser *p);
static expr_ty fstring_replacement_field_rule(Parser *p);
-static expr_ty fstring_conversion_rule(Parser *p);
-static expr_ty fstring_full_format_spec_rule(Parser *p);
+static ResultTokenWithMetadata* fstring_conversion_rule(Parser *p);
+static ResultTokenWithMetadata* fstring_full_format_spec_rule(Parser *p);
static expr_ty fstring_format_spec_rule(Parser *p);
static expr_ty string_rule(Parser *p);
static expr_ty strings_rule(Parser *p);
@@ -15639,11 +15639,11 @@ fstring_replacement_field_rule(Parser *p)
}
D(fprintf(stderr, "%*c> fstring_replacement_field[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'{' (yield_expr | star_expressions) \"=\"? fstring_conversion? fstring_full_format_spec? '}'"));
Token * _literal;
- Token * _literal_1;
void *a;
void *conversion;
void *debug_expr;
void *format;
+ Token * rbrace;
if (
(_literal = _PyPegen_expect_token(p, 25)) // token='{'
&&
@@ -15655,7 +15655,7 @@ fstring_replacement_field_rule(Parser *p)
&&
(format = fstring_full_format_spec_rule(p), !p->error_indicator) // fstring_full_format_spec?
&&
- (_literal_1 = _PyPegen_expect_token(p, 26)) // token='}'
+ (rbrace = _PyPegen_expect_token(p, 26)) // token='}'
)
{
D(fprintf(stderr, "%*c+ fstring_replacement_field[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'{' (yield_expr | star_expressions) \"=\"? fstring_conversion? fstring_full_format_spec? '}'"));
@@ -15668,7 +15668,7 @@ fstring_replacement_field_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro
- _res = _PyPegen_formatted_value ( p , a , debug_expr , conversion , format , EXTRA );
+ _res = _PyPegen_formatted_value ( p , a , debug_expr , conversion , format , rbrace , EXTRA );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;
@@ -15706,7 +15706,7 @@ fstring_replacement_field_rule(Parser *p)
}
// fstring_conversion: "!" NAME
-static expr_ty
+static ResultTokenWithMetadata*
fstring_conversion_rule(Parser *p)
{
if (p->level++ == MAXSTACK) {
@@ -15717,7 +15717,7 @@ fstring_conversion_rule(Parser *p)
p->level--;
return NULL;
}
- expr_ty _res = NULL;
+ ResultTokenWithMetadata* _res = NULL;
int _mark = p->mark;
{ // "!" NAME
if (p->error_indicator) {
@@ -15753,7 +15753,7 @@ fstring_conversion_rule(Parser *p)
}
// fstring_full_format_spec: ':' fstring_format_spec*
-static expr_ty
+static ResultTokenWithMetadata*
fstring_full_format_spec_rule(Parser *p)
{
if (p->level++ == MAXSTACK) {
@@ -15764,7 +15764,7 @@ fstring_full_format_spec_rule(Parser *p)
p->level--;
return NULL;
}
- expr_ty _res = NULL;
+ ResultTokenWithMetadata* _res = NULL;
int _mark = p->mark;
if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) {
p->error_indicator = 1;
@@ -15781,10 +15781,10 @@ fstring_full_format_spec_rule(Parser *p)
return NULL;
}
D(fprintf(stderr, "%*c> fstring_full_format_spec[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "':' fstring_format_spec*"));
- Token * _literal;
+ Token * colon;
asdl_seq * spec;
if (
- (_literal = _PyPegen_expect_token(p, 11)) // token=':'
+ (colon = _PyPegen_expect_token(p, 11)) // token=':'
&&
(spec = _loop0_112_rule(p)) // fstring_format_spec*
)
@@ -15799,7 +15799,7 @@ fstring_full_format_spec_rule(Parser *p)
UNUSED(_end_lineno); // Only used by EXTRA macro
int _end_col_offset = _token->end_col_offset;
UNUSED(_end_col_offset); // Only used by EXTRA macro
- _res = spec ? _PyAST_JoinedStr ( ( asdl_expr_seq* ) spec , EXTRA ) : NULL;
+ _res = _PyPegen_setup_full_format_spec ( p , colon , ( asdl_expr_seq* ) spec , EXTRA );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
p->level--;