mirror of
https://github.com/openharmony/third_party_elfutils.git
synced 2026-07-19 19:43:34 -04:00
2005-09-09 Roland McGrath <roland@redhat.com>
* elf_update.c (write_file): Stat the file and fchmod it after update if its mode had S_ISUID or S_ISGID bits set.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2005-09-09 Roland McGrath <roland@redhat.com>
|
||||
|
||||
* elf_update.c (write_file): Stat the file and fchmod it after update
|
||||
if its mode had S_ISUID or S_ISGID bits set.
|
||||
|
||||
2005-08-28 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* elf32_getphdr.c: Include <system.h>. Use pread_retry instead of
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <libelf.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libelfP.h"
|
||||
|
||||
@@ -31,6 +32,14 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
|
||||
{
|
||||
int class = elf->class;
|
||||
|
||||
/* Check the mode bits now, before modification might change them. */
|
||||
struct stat st;
|
||||
if (unlikely (fstat (elf->fildes, &st) != 0))
|
||||
{
|
||||
__libelf_seterrno (ELF_E_WRITE_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Adjust the size in any case. We do this even if we use `write'.
|
||||
We cannot do this if this file is in an archive. We also don't
|
||||
do it *now* if we are shortening the file since this would
|
||||
@@ -87,6 +96,18 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum)
|
||||
size = -1;
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
if (size != -1
|
||||
&& unlikely (st.st_mode & (S_ISUID | S_ISGID))
|
||||
/* fchmod ignores the bits we cannot change. */
|
||||
&& unlikely (fchmod (elf->fildes, st.st_mode) != 0))
|
||||
{
|
||||
__libelf_seterrno (ELF_E_WRITE_ERROR);
|
||||
size = -1;
|
||||
}
|
||||
|
||||
if (size != -1 && elf->parent == NULL)
|
||||
elf->maximum_size = size;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user