aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-12-04 10:42:07 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-12-04 10:42:07 +0100
commit4bd0c2ab38a53d5ecc89eacc61b3291d4fe01d51 (patch)
treebcba1c6bbae7988c0fe2b8f5375e8b5050a254c4
parentfdb4421e00cc5115cffb55aac79c709a3a5108dd (diff)
downloadbusybox-w32-4bd0c2ab38a53d5ecc89eacc61b3291d4fe01d51.tar.gz
busybox-w32-4bd0c2ab38a53d5ecc89eacc61b3291d4fe01d51.tar.bz2
busybox-w32-4bd0c2ab38a53d5ecc89eacc61b3291d4fe01d51.zip
fix musl problem with dirname, now for all users of bb_make_directory()
function old new delta bb_make_directory 412 419 +7 install_main 793 769 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-24) Total: -17 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/install.c12
-rw-r--r--libbb/make_directory.c15
2 files changed, 16 insertions, 11 deletions
diff --git a/coreutils/install.c b/coreutils/install.c
index d0dcd0e89..831f9b802 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -209,16 +209,10 @@ int install_main(int argc, char **argv)
209 dest = last; 209 dest = last;
210 if (opts & OPT_MKDIR_LEADING) { 210 if (opts & OPT_MKDIR_LEADING) {
211 char *ddir = xstrdup(dest); 211 char *ddir = xstrdup(dest);
212 char *dn = dirname(ddir); 212 bb_make_directory(dirname(ddir), 0755, mkdir_flags);
213 /* musl can return read-only "/" or "." string. 213 /* errors are not checked. copy_file
214 * bb_make_directory needs writable string. 214 * will fail if dir is not created.
215 */ 215 */
216 if ((dn[0] != '/' && dn[0] != '.') || dn[1] != '\0') {
217 bb_make_directory(dn, 0755, mkdir_flags);
218 /* errors are not checked. copy_file
219 * will fail if dir is not created.
220 */
221 }
222 free(ddir); 216 free(ddir);
223 } 217 }
224 if (isdir) 218 if (isdir)
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 89352ca1f..a6b7c28df 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -35,9 +35,20 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
35 char c; 35 char c;
36 struct stat st; 36 struct stat st;
37 37
38 /* Happens on bb_make_directory(dirname("no_slashes"),...) */ 38 /* "path" can be a result of dirname().
39 if (LONE_CHAR(path, '.')) 39 * dirname("no_slashes") returns ".", possibly read-only.
40 * musl dirname() can return read-only "/" too.
41 * We need writable string. And for "/", "." (and ".."?)
42 * nothing needs to be created anyway.
43 */
44 if (LONE_CHAR(path, '/'))
40 return 0; 45 return 0;
46 if (path[0] == '.') {
47 if (path[1] == '\0')
48 return 0; /* "." */
49// if (path[1] == '.' && path[2] == '\0')
50// return 0; /* ".." */
51 }
41 52
42 org_mask = cur_mask = (mode_t)-1L; 53 org_mask = cur_mask = (mode_t)-1L;
43 s = path; 54 s = path;