NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/56398: `mkdir -p -m` fails to assign the correct mode with trailing slashes
>Number: 56398
>Category: bin
>Synopsis: `mkdir -p -m` fails to assign the correct mode with trailing slashes
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Sep 13 01:35:00 +0000 2021
>Originator: Carlo Arenas
>Release: all versions since 2003
>Organization:
>Environment:
NetBSD somehost 9.99.88 NetBSD 9.99.88 (GENERIC) #0: Sun Sep 12 02:20:36 UTC 2021 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
as part of the git testsuite, a test creates a directory where a secure daemon is then started and communicated through a Unix Socket.
the creation of the directory uses :
mkdir -p -m 700 $HOME/dir/
but the daemon fails to start because its directory is not secure, therefore failing the test.
removing the trailing '/' workarounds the problem of course, but the issue should be better fixed at the source.
the problem is NetBSD specific AFAIK, and was probably introduced in revision 1.33
>How-To-Repeat:
diff -urN tests/bin/mkdir/Makefile tests/bin/mkdir/Makefile
--- tests/bin/mkdir/Makefile 1970-01-01 00:00:00.000000000 +0000
+++ tests/bin/mkdir/Makefile 2021-09-12 13:47:31.100158695 +0000
@@ -0,0 +1,6 @@
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/bin/mkdir
+TESTS_SH= t_mkdir
+
+.include <bsd.test.mk>
diff -urN tests/bin/mkdir/t_mkdir.sh tests/bin/mkdir/t_mkdir.sh
--- tests/bin/mkdir/t_mkdir.sh 1970-01-01 00:00:00.000000000 +0000
+++ tests/bin/mkdir/t_mkdir.sh 2021-09-12 14:43:39.719053893 +0000
@@ -0,0 +1,20 @@
+atf_test_case p_and_m
+p_and_m_head() {
+ atf_set "descr" "Ensure that mkdir -p -m keeps track correctly" \
+ "of the last entry even when trailing /"
+ atf_set "use.fs" "true"
+}
+p_and_m_body() {
+ mode="700"
+ atf_check -s eq:0 -o empty -e empty mkdir -p -m $mode foo/bar/
+
+ # ensure that mode was correctly set
+ xmode=$(stat -f "%p" foo/bar)
+ xmode=${xmode#40}
+ atf_check_equal $mode $xmode
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case p_and_m
+}
>Fix:
Index: bin/mkdir/mkdir.c
===================================================================
RCS file: /cvsroot/src/bin/mkdir/mkdir.c,v
retrieving revision 1.38
diff -u -r1.38 mkdir.c
--- bin/mkdir/mkdir.c 29 Aug 2011 14:45:28 -0000 1.38
+++ bin/mkdir/mkdir.c 13 Sep 2021 00:45:47 -0000
@@ -106,16 +106,6 @@
}
for (exitval = EXIT_SUCCESS; *argv != NULL; ++argv) {
-#ifdef notdef
- char *slash;
-
- /* Kernel takes care of this */
- /* Remove trailing slashes, per POSIX. */
- slash = strrchr(*argv, '\0');
- while (--slash > *argv && *slash == '/')
- *slash = '\0';
-#endif
-
if (pflag) {
if (mkpath(*argv, mode, dir_mode) < 0)
exitval = EXIT_FAILURE;
@@ -155,6 +145,10 @@
char *slash;
int done, rv;
+ slash = strrchr(path, '\0');
+ while (--slash > path && *slash == '/')
+ *slash = '\0';
+
done = 0;
slash = path;
Index: etc/mtree/NetBSD.dist.tests
===================================================================
RCS file: /cvsroot/src/etc/mtree/NetBSD.dist.tests,v
retrieving revision 1.188
diff -u -r1.188 NetBSD.dist.tests
--- etc/mtree/NetBSD.dist.tests 29 Aug 2021 09:54:18 -0000 1.188
+++ etc/mtree/NetBSD.dist.tests 13 Sep 2021 00:45:49 -0000
@@ -197,6 +197,7 @@
./usr/tests/bin/dd
./usr/tests/bin/df
./usr/tests/bin/expr
+./usr/tests/bin/mkdir
./usr/tests/bin/pax
./usr/tests/bin/ps
./usr/tests/bin/sleep
Index: tests/bin/Makefile
===================================================================
RCS file: /cvsroot/src/tests/bin/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
--- tests/bin/Makefile 3 Jul 2020 03:59:18 -0000 1.4
+++ tests/bin/Makefile 13 Sep 2021 00:46:03 -0000
@@ -4,6 +4,6 @@
TESTSDIR= ${TESTSBASE}/bin
-TESTS_SUBDIRS= cat cp date dd df expr pax ps sh sleep tar
+TESTS_SUBDIRS= cat cp date dd df expr mkdir pax ps sh sleep tar
.include <bsd.test.mk>
Home |
Main Index |
Thread Index |
Old Index