From 5cbfaeca2a6a809574b6401c3ceb3b916617a8e5 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Tue, 29 Sep 2020 15:58:22 +0100 Subject: [PATCH] resolve-in-sysroot: Don't return real path if not readable The GLib convention is that "out" parameters are untouched on error, and PV_RESOLVE_FLAGS_READABLE makes it an error for the file to be unreadable. Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/resolve-in-sysroot.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pressure-vessel/resolve-in-sysroot.c b/pressure-vessel/resolve-in-sysroot.c index 4b25da6ae..58a74bc77 100644 --- a/pressure-vessel/resolve-in-sysroot.c +++ b/pressure-vessel/resolve-in-sysroot.c @@ -303,9 +303,6 @@ pv_resolve_in_sysroot (int sysroot, } } - if (real_path_out != NULL) - *real_path_out = g_string_free (g_steal_pointer (¤t_path), FALSE); - if (flags & PV_RESOLVE_FLAGS_READABLE) { g_autofree char *proc_fd_name = g_strdup_printf ("/proc/self/fd/%d", @@ -316,9 +313,15 @@ pv_resolve_in_sysroot (int sysroot, if (!glnx_openat_rdonly (-1, proc_fd_name, TRUE, &fd, error)) return -1; + if (real_path_out != NULL) + *real_path_out = g_string_free (g_steal_pointer (¤t_path), FALSE); + return glnx_steal_fd (&fd); } + if (real_path_out != NULL) + *real_path_out = g_string_free (g_steal_pointer (¤t_path), FALSE); + /* Taking the address might look like nonsense here, but it's * documented to work: g_array_index expands to fds->data[some_offset]. * We need to steal ownership of the fd back from @fds so it won't be -- GitLab