From 3f4513d4deaa9eed192fe13b6ce5ad9cb6751917 Mon Sep 17 00:00:00 2001 From: Saracen Date: Tue, 26 Sep 2023 03:07:43 +0100 Subject: [PATCH] Add error checks for DirAccess creation. --- core/config/project_settings.cpp | 1 + editor/editor_node.cpp | 3 +++ editor/editor_settings.cpp | 2 ++ editor/export/editor_export_platform.cpp | 2 ++ editor/filesystem_dock.cpp | 4 ++++ main/main.cpp | 4 ++++ modules/gltf/gltf_document.cpp | 2 ++ platform/android/export/export_plugin.cpp | 4 ++++ scene/resources/resource_format_text.cpp | 2 ++ servers/movie_writer/movie_writer_pngwav.cpp | 2 ++ 10 files changed, 26 insertions(+) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 5ba800ebfeeb..30499942407f 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -962,6 +962,7 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par #ifdef TOOLS_ENABLED bool _csproj_exists(String p_root_dir) { Ref dir = DirAccess::open(p_root_dir); + ERR_FAIL_COND_V(dir.is_null(), false); dir->list_dir_begin(); String file_name = dir->_get_next(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 223e50f557fd..b079277c8bc6 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5954,6 +5954,7 @@ void EditorNode::_dropped_files(const Vector &p_files) { void EditorNode::_add_dropped_files_recursive(const Vector &p_files, String to_path) { Ref dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + ERR_FAIL_COND(dir.is_null()); for (int i = 0; i < p_files.size(); i++) { String from = p_files[i]; @@ -5963,6 +5964,8 @@ void EditorNode::_add_dropped_files_recursive(const Vector &p_files, Str Vector sub_files; Ref sub_dir = DirAccess::open(from); + ERR_FAIL_COND(sub_dir.is_null()); + sub_dir->list_dir_begin(); String next_file = sub_dir->get_next(); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 2c93cc68b075..89a94fe0da19 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -914,6 +914,8 @@ void EditorSettings::create() { if (EditorPaths::get_singleton()->are_paths_valid()) { // Validate editor config file. Ref dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir()); + ERR_FAIL_COND(dir.is_null()); + String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres"; config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name); if (!dir->file_exists(config_file_name)) { diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index b3fefaafc672..6c41e34e5176 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -1383,6 +1383,8 @@ void EditorExportPlatform::zip_folder_recursive(zipFile &p_zip, const String &p_ String dir = p_folder.is_empty() ? p_root_path : p_root_path.path_join(p_folder); Ref da = DirAccess::open(dir); + ERR_FAIL_COND(da.is_null()); + da->list_dir_begin(); String f = da->get_next(); while (!f.is_empty()) { diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 338376c724f5..30d2db8fc717 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1516,6 +1516,8 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin } else { // Recursively duplicate all files inside the folder. Ref old_dir = DirAccess::open(old_path); + ERR_FAIL_COND(old_dir.is_null()); + Ref file_access = FileAccess::create(FileAccess::ACCESS_RESOURCES); old_dir->set_include_navigational(false); old_dir->list_dir_begin(); @@ -3308,6 +3310,8 @@ bool FileSystemDock::_get_imported_files(const String &p_path, String &r_extensi } Ref da = DirAccess::open(p_path); + ERR_FAIL_COND_V(da.is_null(), false); + da->list_dir_begin(); String n = da->get_next(); while (!n.is_empty()) { diff --git a/main/main.cpp b/main/main.cpp index cd9bd6d1d34b..990ef4133a21 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2224,6 +2224,8 @@ Error Main::setup2() { // Editor setting class is not available, load config directly. if (!init_use_custom_screen && (editor || project_manager) && EditorPaths::get_singleton()->are_paths_valid()) { Ref dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir()); + ERR_FAIL_COND_V(dir.is_null(), FAILED); + String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres"; String config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name); if (dir->file_exists(config_file_name)) { @@ -3295,6 +3297,8 @@ bool Main::start() { if (sep == -1) { Ref da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + ERR_FAIL_COND_V(da.is_null(), false); + local_game_path = da->get_current_dir().path_join(local_game_path); } else { Ref da = DirAccess::open(local_game_path.substr(0, sep)); diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index d5dbaf2239ae..7780fac3e0fc 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3051,6 +3051,8 @@ Error GLTFDocument::_serialize_images(Ref p_state) { String relative_texture_dir = "textures"; String full_texture_dir = p_state->base_path.path_join(relative_texture_dir); Ref da = DirAccess::open(p_state->base_path); + ERR_FAIL_COND_V(da.is_null(), FAILED); + if (!da->dir_exists(full_texture_dir)) { da->make_dir(full_texture_dir); } diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 661f7cbc80e2..aeaa7b9ce705 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -2635,6 +2635,8 @@ void EditorExportPlatformAndroid::_clear_assets_directory() { if (da_res->dir_exists(APK_ASSETS_DIRECTORY)) { print_verbose("Clearing APK assets directory..."); Ref da_assets = DirAccess::open(APK_ASSETS_DIRECTORY); + ERR_FAIL_COND(da_assets.is_null()); + da_assets->erase_contents_recursive(); da_res->remove(APK_ASSETS_DIRECTORY); } @@ -2643,6 +2645,8 @@ void EditorExportPlatformAndroid::_clear_assets_directory() { if (da_res->dir_exists(AAB_ASSETS_DIRECTORY)) { print_verbose("Clearing AAB assets directory..."); Ref da_assets = DirAccess::open(AAB_ASSETS_DIRECTORY); + ERR_FAIL_COND(da_assets.is_null()); + da_assets->erase_contents_recursive(); da_res->remove(AAB_ASSETS_DIRECTORY); } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 31f6d6a84a21..dd39f8835294 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1389,6 +1389,8 @@ Error ResourceLoaderText::save_as_binary(const String &p_path) { wf->store_buffer(data.ptr(), data.size()); { Ref dar = DirAccess::open(temp_file.get_base_dir()); + ERR_FAIL_COND_V(dar.is_null(), FAILED); + dar->remove(temp_file); } diff --git a/servers/movie_writer/movie_writer_pngwav.cpp b/servers/movie_writer/movie_writer_pngwav.cpp index 12f338dfb6b9..f0181a216f4b 100644 --- a/servers/movie_writer/movie_writer_pngwav.cpp +++ b/servers/movie_writer/movie_writer_pngwav.cpp @@ -70,6 +70,8 @@ Error MovieWriterPNGWAV::write_begin(const Size2i &p_movie_size, uint32_t p_fps, //Remove existing files before writing anew uint32_t idx = 0; Ref d = DirAccess::open(base_path.get_base_dir()); + ERR_FAIL_COND_V(d.is_null(), FAILED); + String file = base_path.get_file(); while (true) { String path = file + zeros_str(idx) + ".png";