Blob Blame History Raw
From e4928f0ab2b16ded55316cfc44a32f542b88c81f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 20 Jun 2017 15:21:07 -0400
Subject: [PATCH 3/4] cadecoder: only try to set settable chattr bits

We shouldn't be trying to set bits like FS_EXTENT_FL, which chattr(1) says
"cannot be set by chattr", i.e. presumably also not by us. Only compare
and try to set bits which under the FS_FL_USER_MODIFIABLE mask.

Fixes #27.
---
 src/cadecoder.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cadecoder.c b/src/cadecoder.c
index deba462a47..93f8ebf392 100644
--- a/src/cadecoder.c
+++ b/src/cadecoder.c
@@ -3645,15 +3645,18 @@ static int ca_decoder_finalize_child(CaDecoder *d, CaDecoderNode *n, CaDecoderNo
                 int new_attr, old_attr;
 
                 new_attr = ca_feature_flags_to_chattr(read_le64(&child->entry->flags) & d->feature_flags);
+                assert((new_attr & ~FS_FL_USER_MODIFIABLE) == 0);
 
                 if (ioctl(child->fd, FS_IOC_GETFLAGS, &old_attr) < 0) {
 
                         if (new_attr != 0 || !IN_SET(errno, ENOTTY, ENOSYS, EBADF, EOPNOTSUPP))
                                 return -errno;
 
-                } else if (old_attr != new_attr) {
+                } else if ((old_attr & FS_FL_USER_MODIFIABLE) != new_attr) {
+                        int final_attr;
 
-                        if (ioctl(child->fd, FS_IOC_SETFLAGS, &new_attr) < 0)
+                        final_attr = (old_attr & !FS_FL_USER_MODIFIABLE) | new_attr;
+                        if (ioctl(child->fd, FS_IOC_SETFLAGS, &final_attr) < 0)
                                 return -errno;
                 }
         }
-- 
2.13.0