commit:     c8495caa36e7126707854ebb501f62b7f167fffe
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 25 06:07:35 2026 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Wed Feb 25 06:07:35 2026 +0000
URL:        https://gitweb.gentoo.org/proj/install-xattr.git/commit/?id=c8495caa

Ensure loop counters are in bounds

Fixes: f75ba2a6f762 (2026-02-24; "Adjust exclusion logic")
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 install-xattr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/install-xattr.c b/install-xattr.c
index eed0434..7a0a1e5 100644
--- a/install-xattr.c
+++ b/install-xattr.c
@@ -130,19 +130,19 @@ copyxattr(const char *source, const char *target)
        lsize = xlistxattr(source, lxattr, lsize);
 
        for (size_t i = 0;;) {
-               while (lxattr[i] == '\0')
+               while (i < lsize && lxattr[i] == '\0')
                        ++i;
                if (i >= lsize)
                        break;
 
                for (size_t j = 0;;) {
-                       while (exclude[j] == '\0')
+                       while (j < len_exclude && exclude[j] == '\0')
                                ++j;
                        if (j >= len_exclude)
                                break;
                        if (!fnmatch(exclude + j, lxattr + i, 0))
                                goto skip;
-                       while (exclude[j] != '\0')
+                       while (j < len_exclude && exclude[j] != '\0')
                                ++j;
                }
 
@@ -154,7 +154,7 @@ copyxattr(const char *source, const char *target)
                xgetxattr(source, lxattr + i, value, xsize);
                xsetxattr(target, lxattr + i, value, xsize);
  skip:
-               while (lxattr[i] != '\0')
+               while (i < lsize && lxattr[i] != '\0')
                        ++i;
        }
 

Reply via email to