Commit 9e37f5e2 authored by Kevin Wolf's avatar Kevin Wolf

ext2: Handle duplicate dir entries gracefully in unlink

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's avatarKevin Wolf <kevin@tyndur.org>
parent f7e7b624
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment