return (ret);
/*
- * Set the umask to zero so we get predictable mode settings.
+ * Query the umask so we get predictable mode settings.
* This gets done on every call to _write_header in case the
* user edits their umask during the extraction for some
- * reason. This will be reset before we return. Note that we
- * don't need to do this in _finish_entry, as the chmod(), etc,
- * system calls don't obey umask.
+ * reason.
*/
- a->user_umask = umask(0);
- /* From here on, early exit requires "goto done" to clean up. */
+ umask(a->user_umask = umask(0));
/* Figure out what we need to do for this entry. */
a->todo = TODO_MODE_BASE;
if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) {
ret = check_symlinks(a);
if (ret != ARCHIVE_OK)
- goto done;
+ return (ret);
}
#if defined(HAVE_FCHDIR) && defined(PATH_MAX)
/* If path exceeds PATH_MAX, shorten the path. */
archive_entry_set_size(entry, 0);
a->filesize = 0;
}
-done:
- /* Restore the user's umask before returning. */
- umask(a->user_umask);
return (ret);
}
a->lookup_uid = trivial_lookup_uid;
a->lookup_gid = trivial_lookup_gid;
a->start_time = time(NULL);
+ /* Query and restore the umask. */
+ umask(a->user_umask = umask(0));
#ifdef HAVE_GETEUID
a->user_uid = geteuid();
#endif /* HAVE_GETEUID */
* that SUID, SGID, etc, require additional work to ensure
* security, so we never restore them at this point.
*/
- mode = final_mode & 0777;
+ mode = final_mode & 0777 & a->user_umask;
switch (a->mode & AE_IFMT) {
default: