Permalink
Browse files

Fix a double free problem in codegen.c; fix #3378

This issue was first reported by https://hackerone.com/geeknik
The fix was proposed by @titanous
  • Loading branch information...
matz committed Jan 23, 2017
1 parent 3ce8260 commit f0f095bc135c4d2e6f6d54d6b5683db77708369b
Showing with 6 additions and 4 deletions.
  1. +1 −0 include/mruby/irep.h
  2. +1 −3 mrbgems/mruby-compiler/core/codegen.c
  3. +4 −1 src/state.c
View
@@ -39,6 +39,7 @@ typedef struct mrb_irep {
struct mrb_locals *lv;
/* debug info */
mrb_bool own_filename;
const char *filename;
uint16_t *lines;
struct mrb_irep_debug_info* debug_info;
@@ -2844,6 +2844,7 @@ scope_finish(codegen_scope *s)
memcpy(fname, s->filename, fname_len);
fname[fname_len] = '\0';
irep->filename = fname;
irep->own_filename = TRUE;
}
irep->nlocals = s->nlocals;
@@ -2951,9 +2952,6 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
return proc;
}
MRB_CATCH(&scope->jmp) {
if (scope->filename == scope->irep->filename) {
scope->irep->filename = NULL;
}
mrb_irep_decref(mrb, scope->irep);
mrb_pool_close(scope->mpool);
return NULL;
View
@@ -159,7 +159,9 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
}
mrb_free(mrb, irep->reps);
mrb_free(mrb, irep->lv);
mrb_free(mrb, (void *)irep->filename);
if (irep->own_filename) {
mrb_free(mrb, (void *)irep->filename);
}
mrb_free(mrb, irep->lines);
mrb_debug_info_free(mrb, irep->debug_info);
mrb_free(mrb, irep);
@@ -261,6 +263,7 @@ mrb_add_irep(mrb_state *mrb)
irep = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep));
*irep = mrb_irep_zero;
irep->refcnt = 1;
irep->own_filename = FALSE;
return irep;
}

0 comments on commit f0f095b

Please sign in to comment.