From 7d18de7b5c2ff4f91dda92d12005e709f61c0711 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 24 Apr 2019 10:54:31 -0400 Subject: [PATCH] Fix: flt.lttng-utils.debug-info: ".debug" extension not appended Issue ===== The g_strconcat() function returns a newly allocated string and does not change the string in place as the code seems to assume. This results in the call to g_strconcat() having no effects. Because of this, the ".debug" extension is not appended to the file name resulting in a failure find the file on the file system. Ignoring the return value of this call also results in the leaking of the resulting char array. Solution ======== Use g_snprintf() instead to concatenate the file name and its extension. Known drawbacks =============== None. Signed-off-by: Francis Deslauriers --- plugins/lttng-utils/debug-info/bin-info.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/lttng-utils/debug-info/bin-info.c b/plugins/lttng-utils/debug-info/bin-info.c index dd42f41c..023902c7 100644 --- a/plugins/lttng-utils/debug-info/bin-info.c +++ b/plugins/lttng-utils/debug-info/bin-info.c @@ -509,7 +509,7 @@ int bin_info_set_dwarf_info_build_id(struct bin_info *bin) int i = 0, ret = 0; char *path = NULL, *build_id_file = NULL; const char *dbg_dir = NULL; - size_t build_id_file_len; + size_t build_id_char_len, build_id_suffix_char_len, build_id_file_len; if (!bin || !bin->build_id) { goto error; @@ -518,8 +518,9 @@ int bin_info_set_dwarf_info_build_id(struct bin_info *bin) dbg_dir = bin->debug_info_dir ? bin->debug_info_dir : DEFAULT_DEBUG_DIR; /* 2 characters per byte printed in hex, +1 for '/' and +1 for '\0' */ - build_id_file_len = (2 * bin->build_id_len) + 1 + - strlen(BUILD_ID_SUFFIX) + 1; + build_id_char_len = (2 * bin->build_id_len) + 1; + build_id_suffix_char_len = strlen(BUILD_ID_SUFFIX) + 1; + build_id_file_len = build_id_char_len + build_id_suffix_char_len; build_id_file = g_new0(gchar, build_id_file_len); if (!build_id_file) { goto error; @@ -531,7 +532,8 @@ int bin_info_set_dwarf_info_build_id(struct bin_info *bin) g_snprintf(&build_id_file[path_idx], 3, "%02x", bin->build_id[i]); } - g_strconcat(build_id_file, BUILD_ID_SUFFIX, NULL); + g_snprintf(&build_id_file[build_id_char_len], build_id_suffix_char_len, + BUILD_ID_SUFFIX); path = g_build_path("/", dbg_dir, BUILD_ID_SUBDIR, build_id_file, NULL); if (!path) { -- 2.34.1