[FL-3334] Storage: explosive rename fix (#2876)

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov 2023-07-14 12:16:22 +03:00 committed by GitHub
parent 6605740ce9
commit e073c603a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -430,6 +430,20 @@ FS_Error storage_common_rename(Storage* storage, const char* old_path, const cha
break; break;
} }
if(storage_dir_exists(storage, old_path)) {
FuriString* dir_path = furi_string_alloc_set_str(old_path);
if(!furi_string_end_with_str(dir_path, "/")) {
furi_string_cat_str(dir_path, "/");
}
const char* dir_path_s = furi_string_get_cstr(dir_path);
if(strncmp(new_path, dir_path_s, strlen(dir_path_s)) == 0) {
error = FSE_INVALID_NAME;
furi_string_free(dir_path);
break;
}
furi_string_free(dir_path);
}
if(storage_file_exists(storage, new_path)) { if(storage_file_exists(storage, new_path)) {
storage_common_remove(storage, new_path); storage_common_remove(storage, new_path);
} }