unzip: do not set directory mode to 0777
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 6 Feb 2018 16:59:32 +0000 (17:59 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 6 Feb 2018 16:59:32 +0000 (17:59 +0100)
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882177

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/unzip.c
libbb/make_directory.c

index 653fdd10f9a7c9dc9c0d71d6136759cbe40ace53..da4b2a54493062529cd0d5f38c4b15d02ca44b66 100644 (file)
@@ -336,7 +336,9 @@ static void unzip_create_leading_dirs(const char *fn)
 {
        /* Create all leading directories */
        char *name = xstrdup(fn);
-       if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
+
+       /* mode of -1: set mode according to umask */
+       if (bb_make_directory(dirname(name), -1, FILEUTILS_RECUR)) {
                xfunc_die(); /* bb_make_directory is noisy */
        }
        free(name);
index b9916d1654b59e3d40b8edf31cc8780c2221873d..64736efbed194928aee46f97fd6d99ebd4d61ee1 100644 (file)
@@ -92,6 +92,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
                        }
                }
 
+               //bb_error_msg("mkdir '%s'", path);
                if (mkdir(path, 0777) < 0) {
                        /* If we failed for any other reason than the directory
                         * already exists, output a diagnostic and return -1 */
@@ -118,13 +119,16 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
                        /* Done.  If necessary, update perms on the newly
                         * created directory.  Failure to update here _is_
                         * an error. */
-                       if ((mode != -1) && (chmod(path, mode) < 0)) {
-                               fail_msg = "set permissions of";
-                               if (flags & FILEUTILS_IGNORE_CHMOD_ERR) {
-                                       flags = 0;
-                                       goto print_err;
+                       if (mode != -1) {
+                               //bb_error_msg("chmod 0%03lo mkdir '%s'", mode, path);
+                               if (chmod(path, mode) < 0)) {
+                                       fail_msg = "set permissions of";
+                                       if (flags & FILEUTILS_IGNORE_CHMOD_ERR) {
+                                               flags = 0;
+                                               goto print_err;
+                                       }
+                                       break;
                                }
-                               break;
                        }
                        goto ret0;
                }