From 915b1ed7de592361d0e28f8b7301bf7969ff2cb4 Mon Sep 17 00:00:00 2001 From: Rodrigo OSORIO Date: Sat, 23 Aug 2025 17:12:33 +0200 Subject: [PATCH] improve the attribute parsing by reducing to one the memmove calls when converting FreeBSD attribute list to the format used by Linux and extend the rsync unit tests for long xattrs lists. --- lib/sysxattrs.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/sysxattrs.c b/lib/sysxattrs.c index 5a6aeaad..0dc0acea 100644 --- a/lib/sysxattrs.c +++ b/lib/sysxattrs.c @@ -142,15 +142,12 @@ ssize_t sys_llistxattr(const char *path, char *list, size_t size) * terminator. We need to change this into a series of null-terminted * strings. Since the size is the same, we can simply transform the * output in place. */ - for (off = 0; off < len; off += keylen + 1) { - keylen = ((unsigned char*)list)[off]; - if (off + keylen >= len) { - /* Should be impossible, but bugs happen! */ - errno = EINVAL; - return -1; - } - memmove(list+off, list+off+1, keylen); - list[off+keylen] = '\0'; + keylen = (unsigned char)list[0]; + memmove(list, list+1, len-1); + list[len-1] = '\0'; + for (off = keylen; off < (len - 1); off += (keylen + 1)) { + keylen = (unsigned char)list[off]; + list[off] = '\0'; } return len;