From 5e738a2deec976ffac6c313327f407d7e4760076 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 27 Mar 2017 16:33:52 +0200 Subject: Skip fchown, fchmod, fadvise, fallocate if functions are unavailable If fchmod or fchown are unavailable, then the file permission model is likely to be different from what we expect there. posix_fallocate is a rather fragile affair already on linux, and not guaranteed to do anything useful. If it's not available, the result will be the same as when it's available and unreliable. fadvise is an optimization. Change-Id: I28a77e976a0198cf80397b45eb1bc8cfb30664f5 Reviewed-by: Christian Kandeler --- libelf/ChangeLog | 5 +++++ libelf/elf_update.c | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'libelf') diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 0a5200f4..fd20ebb7 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2017-05-04 Ulf Hermann + + * elf_update.c: Don't try to posix_fallocate on systems where it isn't + available. Don't fchmod the output file if there is no fchmod. + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 8ce07829..b6014cdb 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -80,6 +80,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) if (elf->map_address != NULL) { +#if HAVE_DECL_POSIX_FALLOCATE /* When using mmap we want to make sure the file content is really there. Only using ftruncate might mean the file is extended, but space isn't allocated yet. This might cause a @@ -100,6 +101,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); return -1; } +#endif /* The file is mmaped. */ if ((class == ELFCLASS32 @@ -129,6 +131,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) size = -1; } +#if HAVE_DECL_FCHMOD /* POSIX says that ftruncate and write may clear the S_ISUID and S_ISGID mode bits. So make sure we restore them afterwards if they were set. This is not atomic if someone else chmod's the file while we operate. */ @@ -140,6 +143,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); size = -1; } +#endif if (size != -1 && elf->parent == NULL) elf->maximum_size = size; -- cgit v1.2.3