Fix: flt.lttng-utils.debug-info: ".debug" extension not appended
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 24 Apr 2019 14:54:31 +0000 (10:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:39 +0000 (18:19 -0400)
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 <francis.deslauriers@efficios.com>
plugins/lttng-utils/debug-info/bin-info.c

index dd42f41cfbcd6301dcfef11e25964a4edb7f1447..023902c77b900f2248be6093ddb2601293e198cd 100644 (file)
@@ -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) {
This page took 0.026257 seconds and 4 git commands to generate.