diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-04-30 12:16:21 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-04-30 12:16:21 +0900 |
| commit | 1fefa046cd62e0ccf037dcb4ce0739792b620404 (patch) | |
| tree | 7d18005bf3e370e632005c4addce16e821134bc4 /src | |
| parent | 41e69319874e8b975e4fac684ec69c05d33981ed (diff) | |
| parent | 091ce867c104d0b1ad02dd7c34f13eef27b0ff39 (diff) | |
| download | mruby-1fefa046cd62e0ccf037dcb4ce0739792b620404.tar.gz mruby-1fefa046cd62e0ccf037dcb4ce0739792b620404.zip | |
Merge pull request #2774 from cremno/refactor-mrb_read_irep_file
mrb_read_irep_file(): unify error handling / fix uint underflow
Diffstat (limited to 'src')
| -rw-r--r-- | src/load.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/load.c b/src/load.c index 889420ae9..9854f712f 100644 --- a/src/load.c +++ b/src/load.c @@ -670,23 +670,21 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp) /* You don't need use SIZE_ERROR as buf_size is enough small. */ buf = (uint8_t*)mrb_malloc(mrb, header_size); if (fread(buf, header_size, 1, fp) == 0) { - mrb_free(mrb, buf); - return NULL; + goto irep_exit; } result = read_binary_header(buf, &buf_size, NULL, &flags); - if (result != MRB_DUMP_OK) { - mrb_free(mrb, buf); - return NULL; + if (result != MRB_DUMP_OK || buf_size <= header_size) { + goto irep_exit; } buf = (uint8_t*)mrb_realloc(mrb, buf, buf_size); if (fread(buf+header_size, buf_size-header_size, 1, fp) == 0) { - mrb_free(mrb, buf); - return NULL; + goto irep_exit; } irep = read_irep(mrb, buf, FLAG_SRC_MALLOC); - mrb_free(mrb, buf); +irep_exit: + mrb_free(mrb, buf); return irep; } |
