Permalink
Browse files

Merge pull request #239 from thecodeshop/jf/mrb_open

guard mrb_open mem allocation and downstream usage
  • Loading branch information...
matz committed Jun 3, 2012
2 parents 0719f52 + 2fff59d commit d8f1e17ef6282b15c945f1feb5b75c36be96f20e
Showing with 71 additions and 0 deletions.
  1. +5 −0 src/codegen.c
  2. +40 −0 src/gc.c
  3. +5 −0 src/parse.y
  4. +1 −0 src/state.c
  5. +5 −0 test/driver.c
  6. +5 −0 tools/mirb/mirb.c
  7. +5 −0 tools/mrbc/mrbc.c
  8. +5 −0 tools/mruby/mruby.c
View
@@ -2292,6 +2292,11 @@ main()
mrb_state *mrb = mrb_open();
int n;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting codegen test");
+ return EXIT_FAILURE;
+ }
+
#if 1
n = mrb_compile_string(mrb, "p(__FILE__)\np(__LINE__)");
#else
View
@@ -934,6 +934,11 @@ test_mrb_field_write_barrier(void)
mrb_state *mrb = mrb_open();
struct RBasic *obj, *value;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_mrb_field_write_barrier");
+ return;
+ }
+
puts("test_mrb_field_write_barrier");
obj = RBASIC(mrb_ary_new(mrb));
value = RBASIC(mrb_str_new_cstr(mrb, "value"));
@@ -997,6 +1002,11 @@ test_mrb_write_barrier(void)
mrb_state *mrb = mrb_open();
struct RBasic *obj;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_mrb_write_barrier");
+ return;
+ }
+
puts("test_mrb_write_barrier");
obj = RBASIC(mrb_ary_new(mrb));
paint_black(obj);
@@ -1024,6 +1034,11 @@ test_add_gray_list(void)
mrb_state *mrb = mrb_open();
struct RBasic *obj1, *obj2;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_add_gray_list");
+ return;
+ }
+
puts("test_add_gray_list");
gc_assert(mrb->gray_list == NULL);
obj1 = RBASIC(mrb_str_new_cstr(mrb, "test"));
@@ -1048,6 +1063,11 @@ test_gc_gray_mark(void)
struct RBasic *obj;
size_t gray_num = 0;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_gc_gray_mark");
+ return;
+ }
+
puts("test_gc_gray_mark");
puts(" in MRB_TT_CLASS");
@@ -1079,6 +1099,11 @@ test_incremental_gc(void)
RVALUE *free;
struct heap_page *page;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_incremental_gc");
+ return;
+ }
+
puts("test_incremental_gc");
mrb_garbage_collect(mrb);
@@ -1135,6 +1160,11 @@ test_incremental_sweep_phase(void)
{
mrb_state *mrb = mrb_open();
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_incremental_sweep_phase");
+ return;
+ }
+
puts("test_incremental_sweep_phase");
add_heap(mrb);
@@ -1158,6 +1188,11 @@ test_gc_api(void)
mrb_value argv[1];
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test_gc_api");
+ return;
+ }
+
puts("test_gc_api");
gc_start(mrb, mrb_nil_value());
@@ -1191,6 +1226,11 @@ test_many_object_benchmark(void)
mrb_value ary = mrb_ary_new(mrb);
int save_point = mrb_gc_arena_save(mrb);
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, test_many_object_benchmark");
+ return;
+ }
+
puts("test_many_object_benchmark");
for (i=0; i<1000; i++) {
View
@@ -5518,6 +5518,11 @@ main()
mrb_state *mrb = mrb_open();
int n;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting parser test");
+ return EXIT_FAILURE;
+ }
+
n = mrb_compile_string(mrb, "\
def fib(n)\n\
if n<2\n\
View
@@ -16,6 +16,7 @@ mrb_state*
mrb_open_allocf(mrb_allocf f)
{
mrb_state *mrb = (f)(NULL, NULL, sizeof(mrb_state));
+ if (mrb == NULL) return NULL;
memset(mrb, 0, sizeof(mrb_state));
mrb->allocf = f;
View
@@ -36,6 +36,11 @@ main(void)
/* new interpreter instance */
mrb = mrb_open();
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting test driver");
+ return EXIT_FAILURE;
+ }
+
mrb_init_mrbtest(mrb);
parser = mrb_parse_nstring(mrb, prog, strlen(prog));
View
@@ -142,6 +142,11 @@ main(void)
/* new interpreter instance */
mrb_interpreter = mrb_open();
+ if (mrb_interpreter == NULL) {
+ fprintf(stderr, "Invalid mrb_interpreter, exiting mirb");
+ return EXIT_FAILURE;
+ }
+
/* new parser instance */
parser = mrb_parser_new(mrb_interpreter);
memset(ruby_code, 0, sizeof(*ruby_code));
View
@@ -158,6 +158,11 @@ main(int argc, char **argv)
struct _args args;
struct mrb_parser_state *p;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting mrbc");
+ return EXIT_FAILURE;
+ }
+
n = parse_args(mrb, argc, argv, &args);
if (n < 0 || args.rfp == NULL) {
View
@@ -142,6 +142,11 @@ main(int argc, char **argv)
struct _args args;
struct mrb_parser_state *p;
+ if (mrb == NULL) {
+ fprintf(stderr, "Invalid mrb_state, exiting mruby");
+ return EXIT_FAILURE;
+ }
+
n = parse_args(mrb, argc, argv, &args);
if (n < 0 || (args.cmdline == NULL && args.rfp == NULL)) {
cleanup(mrb, &args);

0 comments on commit d8f1e17

Please sign in to comment.