]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libelf: Use posix_fallocate instead of ftruncate to extend ELF file.
authorMark Wielaard <mjw@redhat.com>
Thu, 14 May 2015 10:34:26 +0000 (12:34 +0200)
committerMark Wielaard <mjw@redhat.com>
Wed, 27 May 2015 15:10:48 +0000 (17:10 +0200)
commit77482c4bf63a92166191e0b8531e9781f6fddbf3
treeac8b53653eddd09edc3314fd2af48d55f92af224
parent2b250b759799eaa43bce1643b7072be8c5c19c01
libelf: Use posix_fallocate instead of ftruncate to extend ELF file.

This fixes an obscure SIGBUS error when using ELF_C_WRITE_MMAP on an ELF
file that needs extending when the underlying file system is (nearly) full.

Use posix_fallocate to make sure the file content is really there. Using
ftruncate might mean the file is extended, but space isn't allocated yet.
This might cause a SIGBUS once we write into the mmapped space and the disk
is full.

Using fallocate might fail on some file systems. posix_fallocate is
required to extend the file and allocate enough space even if the
underlying filesystem would normally return EOPNOTSUPP or the kernel
doesn't implement the fallocate syscall. Also posix_fallocate has been in
glibc since 2.1.94, while support for fallocate was only added in 2.10
and kernel 2.6.23.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf_update.c