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>
int i = 0, ret = 0;
char *path = NULL, *build_id_file = NULL;
const char *dbg_dir = NULL;
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;
if (!bin || !bin->build_id) {
goto error;
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' */
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;
build_id_file = g_new0(gchar, build_id_file_len);
if (!build_id_file) {
goto error;
g_snprintf(&build_id_file[path_idx], 3, "%02x", bin->build_id[i]);
}
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) {
path = g_build_path("/", dbg_dir, BUILD_ID_SUBDIR, build_id_file, NULL);
if (!path) {