From dba1fce993b280e2c9481a0d94ec2cc0ddc26739 Mon Sep 17 00:00:00 2001 From: Luke Yue Date: Sun, 30 May 2021 17:51:36 +0800 Subject: [PATCH] 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 --- glib/gutils.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/glib/gutils.c b/glib/gutils.c index f72a5a148..b7a2113d4 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -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; }