From 72ae9ade7e011e56f429e9f593a25fe956964211 Mon Sep 17 00:00:00 2001 From: Yura Pakhuchiy Date: Sat, 22 Sep 2007 23:19:09 +0300 Subject: [PATCH] ntfs_delete: Add sanity check for case when user tries to delete inode with several references --- libntfs/dir.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libntfs/dir.c b/libntfs/dir.c index 124bb860..b2e0763b 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -1453,6 +1453,12 @@ int ntfs_delete(ntfs_inode **pni, ntfs_inode *dir_ni, ntfschar *name, errno = EINVAL; goto err_out; } + if (ni->nr_references > 1 && le16_to_cpu(ni->mrec->link_count) == 1) { + ntfs_log_error("Trying to deleting inode with left " + "references.\n"); + errno = EINVAL; + goto err_out; + } /* * Search for FILE_NAME attribute with such name. If it's in POSIX or * WIN32_AND_DOS namespace, then simply remove it from index and inode. @@ -1546,6 +1552,14 @@ search: } ntfs_attr_close(na); } + /* One more sanity check. */ + if (ni->nr_references > 1 && looking_for_dos_name && + le16_to_cpu(ni->mrec->link_count) == 2) { + ntfs_log_error("Trying to deleting inode with left " + "references.\n"); + errno = EINVAL; + goto err_out; + } ntfs_log_trace("Found!\n"); /* Search for such FILE_NAME in index. */ ictx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4);