|
Kmods SIG |
8b815c |
From cff32466bf851bf29cd491d8a3cbeb4dc4a36ab6 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
8b815c |
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
8b815c |
Date: Fri, 24 Sep 2021 17:53:56 +0300
|
|
Kmods SIG |
8b815c |
Subject: [Backport cff32466bf85] src: Refactoring of ntfs_set_ea
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
Make code more readable.
|
|
Kmods SIG |
8b815c |
Don't try to read zero bytes.
|
|
Kmods SIG |
8b815c |
Add warning when size of exteneded attribute exceeds limit.
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
8b815c |
---
|
|
Kmods SIG |
8b815c |
src/xattr.c | 31 +++++++++++++++++--------------
|
|
Kmods SIG |
8b815c |
1 file changed, 17 insertions(+), 14 deletions(-)
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
diff --git a/src/xattr.c b/src/xattr.c
|
|
Kmods SIG |
8b815c |
index 29f571b53083ea86d3091834749b8d87dec9d69c..cdc01877227a509398c9c8b203382ac2f9858a5e 100644
|
|
Kmods SIG |
8b815c |
--- a/src/xattr.c
|
|
Kmods SIG |
8b815c |
+++ b/src/xattr.c
|
|
Kmods SIG |
8b815c |
@@ -75,6 +75,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
|
|
Kmods SIG |
8b815c |
size_t add_bytes, const struct EA_INFO **info)
|
|
Kmods SIG |
8b815c |
{
|
|
Kmods SIG |
8b815c |
int err;
|
|
Kmods SIG |
8b815c |
+ struct ntfs_sb_info *sbi = ni->mi.sbi;
|
|
Kmods SIG |
8b815c |
struct ATTR_LIST_ENTRY *le = NULL;
|
|
Kmods SIG |
8b815c |
struct ATTRIB *attr_info, *attr_ea;
|
|
Kmods SIG |
8b815c |
void *ea_p;
|
|
Kmods SIG |
8b815c |
@@ -99,10 +100,10 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Check Ea limit. */
|
|
Kmods SIG |
8b815c |
size = le32_to_cpu((*info)->size);
|
|
Kmods SIG |
8b815c |
- if (size > ni->mi.sbi->ea_max_size)
|
|
Kmods SIG |
8b815c |
+ if (size > sbi->ea_max_size)
|
|
Kmods SIG |
8b815c |
return -EFBIG;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
- if (attr_size(attr_ea) > ni->mi.sbi->ea_max_size)
|
|
Kmods SIG |
8b815c |
+ if (attr_size(attr_ea) > sbi->ea_max_size)
|
|
Kmods SIG |
8b815c |
return -EFBIG;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
/* Allocate memory for packed Ea. */
|
|
Kmods SIG |
8b815c |
@@ -110,15 +111,16 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
|
|
Kmods SIG |
8b815c |
if (!ea_p)
|
|
Kmods SIG |
8b815c |
return -ENOMEM;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
- if (attr_ea->non_res) {
|
|
Kmods SIG |
8b815c |
+ if (!size) {
|
|
Kmods SIG |
8b815c |
+ ;
|
|
Kmods SIG |
8b815c |
+ } else if (attr_ea->non_res) {
|
|
Kmods SIG |
8b815c |
struct runs_tree run;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
run_init(&run;;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
err = attr_load_runs(attr_ea, ni, &run, NULL);
|
|
Kmods SIG |
8b815c |
if (!err)
|
|
Kmods SIG |
8b815c |
- err = ntfs_read_run_nb(ni->mi.sbi, &run, 0, ea_p, size,
|
|
Kmods SIG |
8b815c |
- NULL);
|
|
Kmods SIG |
8b815c |
+ err = ntfs_read_run_nb(sbi, &run, 0, ea_p, size, NULL);
|
|
Kmods SIG |
8b815c |
run_close(&run;;
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
if (err)
|
|
Kmods SIG |
8b815c |
@@ -366,21 +368,22 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,
|
|
Kmods SIG |
8b815c |
new_ea->name[name_len] = 0;
|
|
Kmods SIG |
8b815c |
memcpy(new_ea->name + name_len + 1, value, val_size);
|
|
Kmods SIG |
8b815c |
new_pack = le16_to_cpu(ea_info.size_pack) + packed_ea_size(new_ea);
|
|
Kmods SIG |
8b815c |
-
|
|
Kmods SIG |
8b815c |
- /* Should fit into 16 bits. */
|
|
Kmods SIG |
8b815c |
- if (new_pack > 0xffff) {
|
|
Kmods SIG |
8b815c |
- err = -EFBIG; // -EINVAL?
|
|
Kmods SIG |
8b815c |
- goto out;
|
|
Kmods SIG |
8b815c |
- }
|
|
Kmods SIG |
8b815c |
ea_info.size_pack = cpu_to_le16(new_pack);
|
|
Kmods SIG |
8b815c |
-
|
|
Kmods SIG |
8b815c |
/* New size of ATTR_EA. */
|
|
Kmods SIG |
8b815c |
size += add;
|
|
Kmods SIG |
8b815c |
- if (size > sbi->ea_max_size) {
|
|
Kmods SIG |
8b815c |
+ ea_info.size = cpu_to_le32(size);
|
|
Kmods SIG |
8b815c |
+
|
|
Kmods SIG |
8b815c |
+ /*
|
|
Kmods SIG |
8b815c |
+ * 1. Check ea_info.size_pack for overflow.
|
|
Kmods SIG |
8b815c |
+ * 2. New attibute size must fit value from $AttrDef
|
|
Kmods SIG |
8b815c |
+ */
|
|
Kmods SIG |
8b815c |
+ if (new_pack > 0xffff || size > sbi->ea_max_size) {
|
|
Kmods SIG |
8b815c |
+ ntfs_inode_warn(
|
|
Kmods SIG |
8b815c |
+ inode,
|
|
Kmods SIG |
8b815c |
+ "The size of extended attributes must not exceed 64KiB");
|
|
Kmods SIG |
8b815c |
err = -EFBIG; // -EINVAL?
|
|
Kmods SIG |
8b815c |
goto out;
|
|
Kmods SIG |
8b815c |
}
|
|
Kmods SIG |
8b815c |
- ea_info.size = cpu_to_le32(size);
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
update_ea:
|
|
Kmods SIG |
8b815c |
|
|
Kmods SIG |
8b815c |
--
|
|
Kmods SIG |
8b815c |
2.31.1
|
|
Kmods SIG |
8b815c |
|