|
Kmods SIG |
8b815c |
From 8607954cf255329d1c6dfc073ff1508b7585573c Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
8b815c |
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
8b815c |
Date: Mon, 11 Oct 2021 19:43:29 +0300
|
|
Kmods SIG |
8b815c |
Subject: [Backport 8607954cf255] src: Check for NULL pointers in
|
|
Kmods SIG |
8b815c |
ni_try_remove_attr_list
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
Check for potential NULL pointers.
|
|
Kmods SIG |
8b815c |
Print error message if found.
|
|
Kmods SIG |
8b815c |
Thread, that leads to this commit:
|
|
Kmods SIG |
8b815c |
https://lore.kernel.org/ntfs3/227c13e3-5a22-0cba-41eb-fcaf41940711@paragon-software.com/
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
Reported-by: Mohammad Rasim <mohammad.rasim96@gmail.com>
|
|
Kmods SIG |
8b815c |
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
8b815c |
---
|
|
Kmods SIG |
8b815c |
src/frecord.c | 23 ++++++++++++++++++++++-
|
|
Kmods SIG |
8b815c |
1 file changed, 22 insertions(+), 1 deletion(-)
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
diff --git a/src/frecord.c b/src/frecord.c
|
|
Kmods SIG |
8b815c |
index ecb965e4afd075e2e38be7dfda7ad71f3ff1e150..6f47a9c17f896c62e355db7a6948075a88247378 100644
|
|
Kmods SIG |
8b815c |
--- a/src/frecord.c
|
|
Kmods SIG |
8b815c |
+++ b/src/frecord.c
|
|
Kmods SIG |
8b815c |
@@ -705,18 +705,35 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
|
|
Kmods SIG |
8b815c |
continue;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
mi = ni_find_mi(ni, ino_get(&le->ref));
|
|
Kmods SIG |
8b815c |
+ if (!mi) {
|
|
Kmods SIG |
8b815c |
+ /* Should never happened, 'cause already checked. */
|
|
Kmods SIG |
8b815c |
+ goto bad;
|
|
Kmods SIG |
8b815c |
+ }
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
attr = mi_find_attr(mi, NULL, le->type, le_name(le),
|
|
Kmods SIG |
8b815c |
le->name_len, &le->id);
|
|
Kmods SIG |
8b815c |
+ if (!attr) {
|
|
Kmods SIG |
8b815c |
+ /* Should never happened, 'cause already checked. */
|
|
Kmods SIG |
8b815c |
+ goto bad;
|
|
Kmods SIG |
8b815c |
+ }
|
|
Kmods SIG |
8b815c |
asize = le32_to_cpu(attr->size);
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Insert into primary record. */
|
|
Kmods SIG |
8b815c |
attr_ins = mi_insert_attr(&ni->mi, le->type, le_name(le),
|
|
Kmods SIG |
8b815c |
le->name_len, asize,
|
|
Kmods SIG |
8b815c |
le16_to_cpu(attr->name_off));
|
|
Kmods SIG |
8b815c |
- id = attr_ins->id;
|
|
Kmods SIG |
8b815c |
+ if (!attr_ins) {
|
|
Kmods SIG |
8b815c |
+ /*
|
|
Kmods SIG |
8b815c |
+ * Internal error.
|
|
Kmods SIG |
8b815c |
+ * Either no space in primary record (already checked).
|
|
Kmods SIG |
8b815c |
+ * Either tried to insert another
|
|
Kmods SIG |
8b815c |
+ * non indexed attribute (logic error).
|
|
Kmods SIG |
8b815c |
+ */
|
|
Kmods SIG |
8b815c |
+ goto bad;
|
|
Kmods SIG |
8b815c |
+ }
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Copy all except id. */
|
|
Kmods SIG |
8b815c |
+ id = attr_ins->id;
|
|
Kmods SIG |
8b815c |
memcpy(attr_ins, attr, asize);
|
|
Kmods SIG |
8b815c |
attr_ins->id = id;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
@@ -732,6 +749,10 @@ static int ni_try_remove_attr_list(struct ntfs_inode *ni)
|
|
Kmods SIG |
8b815c |
ni->attr_list.dirty = false;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
return 0;
|
|
Kmods SIG |
8b815c |
+bad:
|
|
Kmods SIG |
8b815c |
+ ntfs_inode_err(&ni->vfs_inode, "Internal error");
|
|
Kmods SIG |
8b815c |
+ make_bad_inode(&ni->vfs_inode);
|
|
Kmods SIG |
8b815c |
+ return -EINVAL;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/*
|
|
Kmods SIG |
8b815c |
--
|
|
Kmods SIG |
8b815c |
2.31.1
|
|
Kmods SIG |
8b815c |
|