diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-04-09 09:45:56 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-04-09 09:45:56 -0700 |
| commit | c5c3fa193937b26611db72f925102cb22c8797b4 (patch) | |
| tree | bc894bbb7f31465e75e8c02c8191ff4ba84dc8c7 /src | |
| parent | 8e23410a7a95f36613fb16539d1796df7aad145d (diff) | |
| parent | 337076f9ba9222bb29f49fb5b168d8865a8a95a2 (diff) | |
| download | mruby-c5c3fa193937b26611db72f925102cb22c8797b4.tar.gz mruby-c5c3fa193937b26611db72f925102cb22c8797b4.zip | |
Merge pull request #1164 from h2so5/add-validation-for-c-symbol
Add validation for C language symbol name
Diffstat (limited to 'src')
| -rw-r--r-- | src/dump.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/dump.c b/src/dump.c index 9579dabd4..1d59e667b 100644 --- a/src/dump.c +++ b/src/dump.c @@ -499,6 +499,22 @@ mrb_dump_irep_binary(mrb_state *mrb, size_t start_index, int debug_info, FILE* f return result; } +static int +is_valid_c_symbol_name(const char *name) +{ + const char *c = NULL; + + if (name == NULL || name[0] == '\0') return 0; + if (!ISALPHA(name[0]) && name[0] != '_') return 0; + + c = &name[1]; + for (; *c != '\0'; ++c) { + if (!ISALNUM(*c) && *c != '_') return 0; + } + + return 1; +} + int mrb_dump_irep_cfunc(mrb_state *mrb, size_t start_index, int debug_info, FILE *fp, const char *initname) { @@ -506,7 +522,7 @@ mrb_dump_irep_cfunc(mrb_state *mrb, size_t start_index, int debug_info, FILE *fp size_t bin_size = 0, bin_idx = 0; int result; - if (fp == NULL || initname == NULL) { + if (fp == NULL || initname == NULL || !is_valid_c_symbol_name(initname)) { return MRB_DUMP_INVALID_ARGUMENT; } |
