зеркало из https://github.com/github/ruby.git
Fix Ripper memory allocation size when enabled Universal Parser
The size of `struct parser_params` is 8 bytes difference in `ripper_s_allocate` and `rb_ruby_parser_allocate` when the universal parser is enabled. This causes a situation where `*r->p` is not fully initialized in `ripper_s_allocate` as shown below. ```console (gdb) p *r->p $2 = {heap = 0x0, lval = 0x0, yylloc = 0x0, lex = {strterm = 0x0, gets = 0x0, input = 0, string_buffer = {head = 0x0, last = 0x0}, lastlin e = 0x0, nextline = 0x0, pbeg = 0x0, pcur = 0x0, pend = 0x0, ptok = 0x0, gets_ = {ptr = 0, call = 0x0}, state = EXPR_NONE, paren_nest = 0, lpar _seen = 0, debug = 0, has_shebang = 0, token_seen = 0, token_info_enabled = 0, error_p = 0, cr_seen = 0, value = 0, result = 0, parsing_thread = 0, s_value = 0, s_lvalue = 0, s_value_stack = 2097} ```` This seems to cause `double free or corruption (!prev)` and SEGV. So, fixing this by introduce `rb_ripper_parser_params_allocate` and `rb_ruby_parser_config` functions for Ripper, and `struct parser_params` same size is returned.
This commit is contained in:
Родитель
9e3077a7a6
Коммит
060a71d4e7
|
@ -94,7 +94,8 @@ ripper_s_allocate(VALUE klass)
|
|||
&parser_data_type, r);
|
||||
|
||||
#ifdef UNIVERSAL_PARSER
|
||||
r->p = rb_parser_params_allocate();
|
||||
const rb_parser_config_t *config = rb_ruby_parser_config();
|
||||
r->p = rb_ripper_parser_params_allocate(config);
|
||||
#else
|
||||
r->p = rb_ruby_ripper_parser_allocate();
|
||||
#endif
|
||||
|
|
|
@ -105,6 +105,9 @@ long rb_ruby_ripper_column(rb_parser_t *p);
|
|||
long rb_ruby_ripper_token_len(rb_parser_t *p);
|
||||
rb_parser_string_t *rb_ruby_ripper_lex_lastline(rb_parser_t *p);
|
||||
VALUE rb_ruby_ripper_lex_state_name(struct parser_params *p, int state);
|
||||
#ifdef UNIVERSAL_PARSER
|
||||
rb_parser_t *rb_ripper_parser_params_allocate(const rb_parser_config_t *config);
|
||||
#endif
|
||||
struct parser_params *rb_ruby_ripper_parser_allocate(void);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
#ifdef UNIVERSAL_PARSER
|
||||
const rb_parser_config_t *rb_ruby_parser_config(void);
|
||||
rb_parser_t *rb_parser_params_allocate(void);
|
||||
rb_parser_t *rb_parser_params_new(void);
|
||||
#endif
|
||||
|
|
10
parse.y
10
parse.y
|
@ -16613,6 +16613,16 @@ rb_ruby_ripper_lex_state_name(struct parser_params *p, int state)
|
|||
return rb_parser_lex_state_name(p, (enum lex_state_e)state);
|
||||
}
|
||||
|
||||
#ifdef UNIVERSAL_PARSER
|
||||
rb_parser_t *
|
||||
rb_ripper_parser_params_allocate(const rb_parser_config_t *config)
|
||||
{
|
||||
rb_parser_t *p = (rb_parser_t *)config->calloc(1, sizeof(rb_parser_t));
|
||||
p->config = config;
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct parser_params*
|
||||
rb_ruby_ripper_parser_allocate(void)
|
||||
{
|
||||
|
|
|
@ -685,6 +685,12 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|||
.str_coderange_scan_restartable = str_coderange_scan_restartable,
|
||||
};
|
||||
|
||||
const rb_parser_config_t *
|
||||
rb_ruby_parser_config(void)
|
||||
{
|
||||
return &rb_global_parser_config;
|
||||
}
|
||||
|
||||
rb_parser_t *
|
||||
rb_parser_params_allocate(void)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче