gutils: Fix g_find_program_in_path() to return an absolute path

Fix a possibility of returning a relative path, in case PATH contains
a relative path. According to the doc, the function should return an
absolute path.

Signed-off-by: Christoph Niethammer <christoph.niethammer@gmail.com>
This commit is contained in:
Christoph Niethammer 2022-01-27 03:54:01 +01:00
parent 4d97fef04c
commit 78dc1cc3cd

View File

@ -456,7 +456,14 @@ g_find_program_in_path (const gchar *program)
!g_file_test (startp, G_FILE_TEST_IS_DIR)) !g_file_test (startp, G_FILE_TEST_IS_DIR))
{ {
gchar *ret; gchar *ret;
if (g_path_is_absolute (startp)) {
ret = g_strdup (startp); ret = g_strdup (startp);
} else {
gchar *cwd = NULL;
cwd = g_get_current_dir ();
ret = g_build_filename (cwd, startp, NULL);
g_free (cwd);
}
g_free (freeme); g_free (freeme);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
g_free ((gchar *) path_copy); g_free ((gchar *) path_copy);