[cdi-devel] [PATCH 1/2] ext2: Handle duplicate dir entries gracefully in unlink
Kevin Wolf ·
It shouldn't normally happen that there are two directory entries with the same name, but in order to avoid crashes on inconsistent file systems, let's make sure to free the right resource instead of just one with the same name. Also, remove only one directory entry so that another unlink() request can succeed and fully remove the second entry. Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- ext2/libext2/directory.c | 2 +- ext2/res.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext2/libext2/directory.c b/ext2/libext2/directory.c index 54ffffa..f9ffb42 100644 --- a/ext2/libext2/directory.c +++ b/ext2/libext2/directory.c @@ -241,7 +241,7 @@ int ext2_dir_unlink(ext2_inode_t* dir, const char* name) uint32_t bgnum; ext2_inode_readdata(dir, 0, dir->raw->size, buf); - while (pos < dir->raw->size) { + while (!ret && pos < dir->raw->size) { entry = (ext2_dirent_t*) &buf[pos]; // Eintrag als unbenutzt markieren diff --git a/ext2/res.c b/ext2/res.c index 9511098..a127450 100644 --- a/ext2/res.c +++ b/ext2/res.c @@ -383,7 +383,7 @@ int ext2_fs_res_remove(struct cdi_fs_stream* stream) for (i = 0; parent_res->res.children && (child_res = cdi_list_get(parent_res->res.children, i)); i++) { - if (!strcmp(child_res->res.name, res->res.name)) { + if (child_res == res) { cdi_list_remove(parent_res->res.children, i); break; } -- 2.1.4