aboutsummaryrefslogtreecommitdiffstats
path: root/addr2line.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-26 09:28:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-26 09:28:46 +0000
commita879a5f9c428e9c6d975c1e6874da0398a889df5 (patch)
treebaa3d83c344c53ef9a3b5913a44268426c248921 /addr2line.c
parent606363ed1d1a6eecd27e43c41cd5bddb32c98e96 (diff)
downloadruby-a879a5f9c428e9c6d975c1e6874da0398a889df5.tar.gz
get rid of strcpy
* addr2line.c (follow_debuglink): insert global_debug_dir by using memmove instead of copying to temporary buffer. * dln.c (dln_load): use memcpy with the known length instead of strcpy. * gc.c (rb_gc_unprotect_logging): use strdup instead of malloc and strcpy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'addr2line.c')
-rw-r--r--addr2line.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/addr2line.c b/addr2line.c
index 3cfb199d8b..55cc997f77 100644
--- a/addr2line.c
+++ b/addr2line.c
@@ -427,22 +427,25 @@ fill_lines(int num_traces, void **traces, int check_debuglink,
obj_info_t **objp, line_info_t *lines, int offset);
static void
-append_obj(obj_info_t **objp) {
+append_obj(obj_info_t **objp)
+{
obj_info_t *newobj = calloc(1, sizeof(obj_info_t));
if (*objp) (*objp)->next = newobj;
*objp = newobj;
}
static void
-follow_debuglink(char *debuglink, int num_traces, void **traces,
+follow_debuglink(const char *debuglink, int num_traces, void **traces,
obj_info_t **objp, line_info_t *lines, int offset)
{
/* Ideally we should check 4 paths to follow gnu_debuglink,
but we handle only one case for now as this format is used
by some linux distributions. See GDB's info for detail. */
static const char global_debug_dir[] = "/usr/lib/debug";
- char *p, *subdir;
+ const size_t global_debug_dir_len = sizeof(global_debug_dir) - 1;
+ char *p;
obj_info_t *o1 = *objp, *o2;
+ size_t len;
p = strrchr(binary_filename, '/');
if (!p) {
@@ -450,11 +453,13 @@ follow_debuglink(char *debuglink, int num_traces, void **traces,
}
p[1] = '\0';
- subdir = (char *)alloca(strlen(binary_filename) + 1);
- strcpy(subdir, binary_filename);
- strcpy(binary_filename, global_debug_dir);
- strlcat(binary_filename, subdir, PATH_MAX);
- strlcat(binary_filename, debuglink, PATH_MAX);
+ len = strlen(binary_filename);
+ if (len >= PATH_MAX - global_debug_dir_len)
+ len = PATH_MAX - global_debug_dir_len - 1;
+ memmove(binary_filename + global_debug_dir_len, binary_filename, len);
+ memcpy(binary_filename, global_debug_dir, global_debug_dir_len);
+ len += global_debug_dir_len;
+ strlcpy(binary_filename + len, debuglink, PATH_MAX - len);
append_obj(objp);
o2 = *objp;
@@ -726,7 +731,7 @@ rb_dump_backtrace_with_lines(int num_traces, void **traces)
path = info.dli_fname;
obj->path = path;
lines[i].path = path;
- strcpy(binary_filename, path);
+ strlcpy(binary_filename, path, PATH_MAX);
if (fill_lines(num_traces, traces, 1, &obj, lines, i) == (uintptr_t)-1)
break;
}