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