commit d0ad1e42d9fc6447c24619c9694a43f8c02bfc77
parent 59bdce950336ad6f60f91e8eadd07a79febeecb2
Author: Michalis Kokologiannakis <mixaskok@gmail.com>
Date: Tue, 28 Jul 2020 11:05:52 +0300
files: ignore only EPERM when fchmod() or fchown() fails
While ignoring permission errors from fchmod() and fchown() is okay
(since normal users are not always privileged to make such changes),
ignoring also more serious errors (like EIO) is not ideal.
Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -1619,14 +1619,20 @@ bool make_backup_of(char *realname)
goto problem;
/* Try to change owner and group to those of the original file;
- * ignore errors, as a normal user cannot change the owner. */
- IGNORE_CALL_RESULT(fchown(descriptor, openfile->statinfo->st_uid,
- openfile->statinfo->st_gid));
+ * ignore permission errors, as a normal user cannot change the owner. */
+ if (fchown(descriptor, openfile->statinfo->st_uid,
+ openfile->statinfo->st_gid) < 0 && errno != EPERM) {
+ fclose(backup_file);
+ goto problem;
+ }
/* Set the backup's permissions to those of the original file.
* It is not a security issue if this fails, as we have created
* the file with just read and write permission for the owner. */
- IGNORE_CALL_RESULT(fchmod(descriptor, openfile->statinfo->st_mode));
+ if (fchmod(descriptor, openfile->statinfo->st_mode) < 0 && errno != EPERM) {
+ fclose(backup_file);
+ goto problem;
+ }
original = fopen(realname, "rb");