aide/backport-Fix-concurrent-reading-of-extended-attributes-xattrs.patch
2025-03-25 15:24:43 +08:00

58 lines
1.6 KiB
Diff

From 93831c717eaaa19d58da12ebeb28607cc6d43116 Mon Sep 17 00:00:00 2001
From: Hannes von Haugwitz <hannes@vonhaugwitz.com>
Date: Wed, 8 May 2024 23:20:41 +0200
Subject: [PATCH] Fix concurrent reading of extended attributes (xattrs)
---
src/do_md.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/do_md.c b/src/do_md.c
index 20e62f9..4ff2a86 100644
--- a/src/do_md.c
+++ b/src/do_md.c
@@ -482,14 +482,13 @@ static void xattr_add(xattrs_type *xattrs, const char *key, const char
void xattrs2line(db_line *line) {
/* get all generic user xattrs. */
xattrs_type *xattrs = NULL;
- static ssize_t xsz = 1024;
- static char *xatrs = NULL;
ssize_t xret = -1;
if (!(ATTR(attr_xattrs)&line->attr))
return;
- if (!xatrs) xatrs = checked_malloc(xsz);
+ ssize_t xsz = 1024;
+ char *xatrs = xatrs = checked_malloc(xsz);
while (((xret = llistxattr(line->fullpath, xatrs, xsz)) == -1) && (errno == ERANGE)) {
xsz <<= 1;
@@ -502,10 +501,8 @@ void xattrs2line(db_line *line) {
log_msg(LOG_LEVEL_WARNING, "listxattrs failed for %s:%s", line->fullpath, strerror(errno));
} else if (xret) {
const char *attr = xatrs;
- static ssize_t asz = 1024;
- static char *val = NULL;
-
- if (!val) val = checked_malloc(asz);
+ ssize_t asz = 1024;
+ char *val = checked_malloc(asz);
xattrs = xattr_new();
@@ -533,8 +530,9 @@ next_attr:
attr += len + 1;
xret -= len + 1;
}
+ free(val);
}
-
+ free(xatrs);
line->xattrs = xattrs;
}
#endif
--
2.33.0