diff options
author | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:33 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:33 +0530 |
commit | 014cc7f849e8209623fc99264814bce7b3b6faf2 (patch) | |
tree | 890c586d1a37643dfa2aa394935748a5e6542f51 /binutils/bucomm.h | |
parent | 1a1c3b4cc17687091cff5a368bd6f13742bcfdf8 (diff) | |
download | gdb-014cc7f849e8209623fc99264814bce7b3b6faf2.zip gdb-014cc7f849e8209623fc99264814bce7b3b6faf2.tar.gz gdb-014cc7f849e8209623fc99264814bce7b3b6faf2.tar.bz2 |
binutils: Make smart_rename safe too
smart_rename is capable of handling symlinks by copying and it also
tries to preserve ownership and permissions of files when they're
overwritten during the rename. This is useful in objcopy where the
file properties need to be preserved.
However because smart_rename does this using file names, it leaves a
race window between renames and permission fixes. This change removes
this race window by using file descriptors from the original BFDs that
were used to manipulate these files wherever possible.
The file that is to be renamed is also passed as a file descriptor so
that we use fchown/fchmod on the file descriptor, thus making sure
that we only modify the file we have opened to write. Further, in
case the file is to be overwritten (as is the case in ar or objcopy),
the permissions that need to be restored are taken from the file
descriptor that was opened for input so that integrity of the file
status is maintained all the way through to the rename.
binutils/
* rename.c
* ar.c
(write_archive) [!defined (_WIN32) || defined (__CYGWIN32__)]:
Initialize TARGET_STAT and OFD to pass to SMART_RENAME.
* arsup.c
(ar_save) [defined (_WIN32) || defined (__CYGWIN32__)]:
Likewise.
* bucomm.h (smart_rename): Add new arguments to declaration.
* objcopy.c
(strip_main)[defined (_WIN32) || defined (__CYGWIN32__)]:
Initialize COPYFD and pass to SMART_RENAME.
(copy_main) [defined (_WIN32) || defined (__CYGWIN32__)]:
Likewise.
* rename.c (try_preserve_permissions): New function.
(smart_rename): Use it and add new arguments.
Diffstat (limited to 'binutils/bucomm.h')
-rw-r--r-- | binutils/bucomm.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/binutils/bucomm.h b/binutils/bucomm.h index afb8e09..9613b92 100644 --- a/binutils/bucomm.h +++ b/binutils/bucomm.h @@ -71,7 +71,8 @@ extern void print_version (const char *); /* In rename.c. */ extern void set_times (const char *, const struct stat *); -extern int smart_rename (const char *, const char *, int); +extern int smart_rename (const char *, const char *, int, struct stat *, int); + /* In libiberty. */ void *xmalloc (size_t); |