diff options
| author | cremno <[email protected]> | 2014-11-26 00:54:55 +0100 |
|---|---|---|
| committer | cremno <[email protected]> | 2014-12-02 00:00:55 +0100 |
| commit | f31733045feee3c381ee350be64e1a83682d5543 (patch) | |
| tree | f31d868b8dba8783112cbce425cf8fc4a62b2c5c /mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c | |
| parent | ce5a3dbcbaae84d87c4f09d4e28523a59886c7ad (diff) | |
| download | mruby-f31733045feee3c381ee350be64e1a83682d5543.tar.gz mruby-f31733045feee3c381ee350be64e1a83682d5543.zip | |
use mrb_debug_strdup() and mrb_debug_strndup()
As they are safer to use than mrb_malloc()+strlen()+strncpy() (see #2652).
Diffstat (limited to 'mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c')
| -rwxr-xr-x | mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c index 734f03f0a..8eddc7b78 100755 --- a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c +++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c @@ -9,6 +9,7 @@ #include "mrdb.h" #include "mrdberror.h" #include "apilist.h" +#include "apistring.h" #include "mruby/compile.h" #include "mruby/irep.h" #include "mruby/debug.h" @@ -64,7 +65,7 @@ static char* dirname(mrb_state *mrb, const char *path) { size_t len; - char *p, *dir; + char *p; if (path == NULL) { return NULL; @@ -73,11 +74,7 @@ dirname(mrb_state *mrb, const char *path) p = strrchr(path, '/'); len = p != NULL ? p - path : strlen(path); - if ((dir = mrb_malloc(mrb, len + 1)) != NULL) { - strncpy(dir, path, len); - dir[len] = '\0'; - } - return dir; + return mrb_debug_strndup(mrb, path, len); } static source_file* @@ -98,8 +95,10 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename) } file->lineno = 1; - file->path = mrb_malloc(mrb, strlen(filename) + 1); - strcpy(file->path, filename); + if ((file->path = mrb_debug_strdup(mrb, filename)) == NULL) { + source_file_free(mrb, file); + return NULL; + } return file; } |
