[PATCH] binutils: Attempt to retain permissions on copying file

Alan Modra amodra@gmail.com
Wed Feb 24 23:47:31 GMT 2021


On Wed, Feb 24, 2021 at 03:57:10PM +0530, Siddhesh Poyarekar wrote:
> On 2/23/21 5:26 PM, Alan Modra wrote:
> > On Tue, Feb 23, 2021 at 12:22:59PM +0530, Siddhesh Poyarekar wrote:
> > > Writing into an existing file clears its S_ISUID and S_ISGID bits.
> > > Attempt to restore those permission bits but don't fail if it doesn't
> > > work.
> > > 
> > > Also, since the output file always exists (all callers create an empty
> > > file before calling smart_rename), open the file without any
> > > permission hints or O_CREAT.
> > > 
> > > binutils/
> > > 
> > > 	* rename.c (simple_copy): Don't use O_CREAT.
> > > 	(simple_copy)[!defined (_WIN32) || defined (__CYGWIN32__)]:
> > > 	Attempt to retain permission bits.
> > 
> > Thanks, I'll fold this into a followup patch of mine that makes use of
> > the temp file descriptor in smart_rename rather than reopening the
> > file.  I don't believe there is a security issue in reopening the
> > file, but this way there is one less directory operation.  I'm also
> > going to make use of the target_stat we already have rather than
> > calling stat again.
> 
> I just tested tip and it looks in good shape.  I suppose this ought to go
> into 2.36 too since the simple_copy patch went in there too.

I thought we had reverted all the rename.c changes on the branch?

Anyway, the following needs to go on mainline, illustrating why it's
not a good idea to rush patches into a stable branch.  Applied.

	PR 27456
	* rename.c (simple_copy): Mark target_stat ATTRIBUTE_UNUSED.

diff --git a/binutils/rename.c b/binutils/rename.c
index f688f350d5..861c2b56d1 100644
--- a/binutils/rename.c
+++ b/binutils/rename.c
@@ -35,7 +35,8 @@
    Return 0 if ok, -1 if error.  */
 
 static int
-simple_copy (int fromfd, const char *to, struct stat *target_stat)
+simple_copy (int fromfd, const char *to,
+	     struct stat *target_stat ATTRIBUTE_UNUSED)
 {
   int tofd, nread;
   int saved;


-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list