ksh mkdir builtin doesn't honor special file permissions
mkdir ksh builtin misbehaves in a following way:
# /usr/bin/sh $ export PATH=/bin $ id uid=0(root) gid=0(root) $ mkdir -m 1777 /tmp/111 $ ls -ld /tmp/111 drwxrwxrwx 2 root root 117 Sep 26 14:44 /tmp/111 $ rmdir /tmp/111 $ /bin/mkdir -m 1777 /tmp/111 $ ls -ld /tmp/111 drwxrwxrwt 2 root root 117 Sep 26 14:54 /tmp/111
Updated by Peter Tribble about 2 months ago
A quick look at usr/src/lib/libcmd/common/mkdir.c indicates a problem - it looks like chmod() is only called to fix up the permissions on the last entry of a hierarchy created with the -p flag, where the immediate parent doesn't exist.
To confirm this,
$ mkdir -m 1777 -p /tmp/111/222
$ ls -ld /tmp/111/222
drwxrwxrwt 2 ptribble it 117 Sep 26 21:53 /tmp/111/222
Another thing I notice is that mkdir(2) claims that the supplied mode is applied to the directory, which is clearly incorrect - special bits are stripped from the mode and need to be put back with an explicit chmod().