install: fix musl problem with dirname
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Dec 2016 10:49:23 +0000 (11:49 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 3 Dec 2016 10:49:23 +0000 (11:49 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/install.c

index e68589229eb9f1b858daac78f492bb8c9ec0118a..d0dcd0e8957663e7f3f173d5f649bf6ae5e69ee6 100644 (file)
@@ -209,9 +209,16 @@ int install_main(int argc, char **argv)
                        dest = last;
                        if (opts & OPT_MKDIR_LEADING) {
                                char *ddir = xstrdup(dest);
-                               bb_make_directory(dirname(ddir), 0755, mkdir_flags);
-                               /* errors are not checked. copy_file
-                                * will fail if dir is not created. */
+                               char *dn = dirname(ddir);
+                               /* musl can return read-only "/" or "." string.
+                                * bb_make_directory needs writable string.
+                                */
+                               if ((dn[0] != '/' && dn[0] != '.') || dn[1] != '\0') {
+                                       bb_make_directory(dn, 0755, mkdir_flags);
+                                       /* errors are not checked. copy_file
+                                        * will fail if dir is not created.
+                                        */
+                               }
                                free(ddir);
                        }
                        if (isdir)