forked from tytso/e2fsprogs-inline-patch-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
31-libext2fs-xattr-free-before-read.patch
67 lines (59 loc) · 1.77 KB
/
31-libext2fs-xattr-free-before-read.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From: Darrick J. Wong <darrick.wong@oracle.com>
libext2fs: free key/value pairs before reading
Before loading extended attributes, free any key/value pairs that
might already be associated with the file.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index 934ad6f..0e9a9ab 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -654,6 +654,20 @@ static errcode_t read_xattrs_from_buffer(struct ext2_xattr_handle *handle,
return 0;
}
+static void xattrs_free_keys(struct ext2_xattr_handle *h)
+{
+ struct ext2_xattr *a = h->attrs;
+ size_t i;
+
+ for (i = 0; i < h->length; i++) {
+ if (a[i].name)
+ ext2fs_free_mem(&a[i].name);
+ if (a[i].value)
+ ext2fs_free_mem(&a[i].value);
+ }
+ h->count = 0;
+}
+
errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle)
{
struct ext2_xattr *attrs = NULL, *x;
@@ -679,6 +693,8 @@ errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle)
if (err)
goto out;
+ xattrs_free_keys(handle);
+
/* Does the inode have size for EA? */
if (EXT2_INODE_SIZE(handle->fs->super) <= EXT2_GOOD_OLD_INODE_SIZE +
inode->i_extra_isize +
@@ -919,9 +935,7 @@ errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle)
{
- unsigned int i;
struct ext2_xattr_handle *h = *handle;
- struct ext2_xattr *a = h->attrs;
errcode_t err;
if (h->dirty) {
@@ -930,13 +944,7 @@ errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle)
return err;
}
- for (i = 0; i < h->length; i++) {
- if (a[i].name)
- ext2fs_free_mem(&a[i].name);
- if (a[i].value)
- ext2fs_free_mem(&a[i].value);
- }
-
+ xattrs_free_keys(h);
ext2fs_free_mem(&h->attrs);
ext2fs_free_mem(handle);
return 0;