Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14971 > unrolled thread

Re: difference between /tmp and other directory for loadable mkdir?

Started byChet Ramey <chet.ramey@case.edu>
First post2018-12-27 14:50 -0500
Last post2018-12-27 14:50 -0500
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: difference between /tmp and other directory for loadable mkdir? Chet Ramey <chet.ramey@case.edu> - 2018-12-27 14:50 -0500

#14971 — Re: difference between /tmp and other directory for loadable mkdir?

FromChet Ramey <chet.ramey@case.edu>
Date2018-12-27 14:50 -0500
SubjectRe: difference between /tmp and other directory for loadable mkdir?
Message-ID<mailman.6408.1545940237.1284.bug-bash@gnu.org>
On 12/26/18 2:56 PM, Eduardo A. Bustamante López wrote:
> On Wed, Dec 26, 2018 at 12:40:09PM -0600, Peng Yu wrote:
>> Hi,
>>
>> I can not mkdir -p . in /tmp/ via the loadable mkdir. What is the
>> difference between /tmp/ and other directories? I am on Mac OS X. Is
>> this a bug in mkdir?

The difference between /tmp and your home directory, at least in this
case, is that /tmp has the sticky bit (S_ISVTX) set.


> mkdir("/tmp/", 0777)                    = -1 EEXIST (File exists)
> stat("/tmp/", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
> +++ exited with 0 +++
> 
> 
> My guess is that the "problem" has to do with how bash computes the `parent_mode':
> 
> dualbus@debian:~/src/gnu/bash$ cat -n examples/loadables/mkdir.c | sed -n '106,114p'
>    106	  /* Make the new mode */
>    107	  original_umask = umask (0);
>    108	  umask (original_umask);
>    109	
>    110	  nmode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~original_umask;
>    111	  parent_mode = nmode | (S_IWUSR|S_IXUSR);	/* u+wx */
>    112	
>    113	  /* Adjust new mode based on mode argument */
>    114	  nmode &= omode;

That's the POSIX algorithm for creating the intermediate directories and
setting the mode of the final created directory:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html#tag_20_79

but the code should probably perform the mkdir and chmod separately, as the
text suggests.

In any event, that's not the problem. The existing code tries to chmod the
directory even if it already exists, and doesn't take the non-permission
bits (SVTX/SUID/SGID) into account, as POSIX says it shouldn't. It should
probably attempt the chmod only if the user has specified a mode using
`-m mode'.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web