gutils: ensure g_find_program_in_path() return an absolute path

Fix a possibility of returning a relative path, according to the
doc, the function should return an absolute path.

Signed-off-by: Luke Yue <lukedyue@gmail.com>
This commit is contained in:
Luke Yue 2021-05-30 17:51:36 +08:00
parent 11c0b2e597
commit dba1fce993

View File

@ -340,7 +340,17 @@ g_find_program_in_path (const gchar *program)
{
if (g_file_test (program, G_FILE_TEST_IS_EXECUTABLE) &&
!g_file_test (program, G_FILE_TEST_IS_DIR))
return g_strdup (program);
{
gchar *out = NULL, *cwd = NULL;
if (g_path_is_absolute (program))
return g_strdup (program);
cwd = g_get_current_dir ();
out = g_build_filename (cwd, program, NULL);
g_free (cwd);
return g_steal_pointer (&out);
}
else
return NULL;
}