From d70b82237d5fff3d5a2ba663b355dc445f9723b9 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 2 Jun 2022 20:28:25 +0200 Subject: [PATCH] context, instance: Don't ignore errors when creating directories Of the 19 instances where g_mkdir_with_parents() is used, these are the only ones where the return value is ignored. This triggers Coverity. It might not be strictly necessary to handle the errors, but doing so can only help with debugging. --- common/flatpak-context.c | 18 ++++++++++++++---- common/flatpak-instance.c | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/flatpak-context.c b/common/flatpak-context.c index dfec7ffa..a994c047 100644 --- a/common/flatpak-context.c +++ b/common/flatpak-context.c @@ -2538,7 +2538,10 @@ flatpak_context_export (FlatpakContext *context, subpath = g_build_filename (path, rest, NULL); if (mode == FLATPAK_FILESYSTEM_MODE_CREATE && do_create) - g_mkdir_with_parents (subpath, 0755); + { + if (g_mkdir_with_parents (subpath, 0755) != 0) + g_debug ("Unable to create directory %s", subpath); + } if (g_file_test (subpath, G_FILE_TEST_EXISTS)) { @@ -2556,7 +2559,10 @@ flatpak_context_export (FlatpakContext *context, path = g_build_filename (g_get_home_dir (), filesystem + 2, NULL); if (mode == FLATPAK_FILESYSTEM_MODE_CREATE && do_create) - g_mkdir_with_parents (path, 0755); + { + if (g_mkdir_with_parents (path, 0755) != 0) + g_debug ("Unable to create directory %s", path); + } if (g_file_test (path, G_FILE_TEST_EXISTS)) flatpak_exports_add_path_expose_or_hide (exports, mode, path); @@ -2564,7 +2570,10 @@ flatpak_context_export (FlatpakContext *context, else if (g_str_has_prefix (filesystem, "/")) { if (mode == FLATPAK_FILESYSTEM_MODE_CREATE && do_create) - g_mkdir_with_parents (filesystem, 0755); + { + if (g_mkdir_with_parents (filesystem, 0755) != 0) + g_debug ("Unable to create directory %s", filesystem); + } if (g_file_test (filesystem, G_FILE_TEST_EXISTS)) flatpak_exports_add_path_expose_or_hide (exports, mode, filesystem); @@ -2693,7 +2702,8 @@ flatpak_context_append_bwrap_filesystem (FlatpakContext *context, g_autofree char *src = g_build_filename (g_get_home_dir (), ".var/app", app_id, persist, NULL); g_autofree char *dest = g_build_filename (g_get_home_dir (), persist, NULL); - g_mkdir_with_parents (src, 0755); + if (g_mkdir_with_parents (src, 0755) != 0) + g_debug ("Unable to create directory %s", src); flatpak_bwrap_add_bind_arg (bwrap, "--bind", src, dest); } diff --git a/common/flatpak-instance.c b/common/flatpak-instance.c index 234a4b8b..2e4bcb33 100644 --- a/common/flatpak-instance.c +++ b/common/flatpak-instance.c @@ -730,7 +730,8 @@ flatpak_instance_allocate_id (char **host_dir_out, g_return_val_if_fail (lock_fd_out != NULL, NULL); g_return_val_if_fail (*lock_fd_out == -1, NULL); - g_mkdir_with_parents (base_dir, 0755); + if (g_mkdir_with_parents (base_dir, 0755) != 0) + return NULL; flatpak_instance_iterate_all_and_gc (NULL);