+2018-07-21 Mark Wielaard <mark@klomp.org>
+
+ * elfcompress.c (process_file): Swap fchmod and fchown calls.
+
2018-07-04 Mark Wielaard <mark@klomp.org>
* readelf.c (print_debug_addr_section): Rename index var to uidx.
elf_end (elfnew);
elfnew = NULL;
- /* Try to match mode and owner.group of the original file. */
- if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0)
- if (verbose >= 0)
- error (0, errno, "Couldn't fchmod %s", fnew);
+ /* Try to match mode and owner.group of the original file.
+ Note to set suid bits we have to make sure the owner is setup
+ correctly first. Otherwise fchmod will drop them silently
+ or fchown may clear them. */
if (fchown (fdnew, st.st_uid, st.st_gid) != 0)
if (verbose >= 0)
error (0, errno, "Couldn't fchown %s", fnew);
+ if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0)
+ if (verbose >= 0)
+ error (0, errno, "Couldn't fchmod %s", fnew);
/* Finally replace the old file with the new file. */
if (foutput == NULL)