GNU bug report logs -
#24659
'mkdir' procedure is neither thread-safe nor safe (2.0.12)
Previous Next
Reported by: ludo <at> gnu.org (Ludovic Courtès)
Date: Mon, 10 Oct 2016 16:41:02 UTC
Severity: important
Fixed in version 2.0.13
Done: ludo <at> gnu.org (Ludovic Courtès)
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Hello!
When the optional ‘mode’ argument to the ‘mkdir’ procedure is omitted,
umask(2) is used to find out what the current mask is and to compute the
mode argument to mkdir(2):
--8<---------------cut here---------------start------------->8---
if (SCM_UNBNDP (mode))
{
mask = umask (0);
umask (mask);
STRING_SYSCALL (path, c_path, rv = mkdir (c_path, 0777 ^ mask));
}
--8<---------------cut here---------------end--------------->8---
The problem is that this changes the process’ umask globally for a short
duration, during which other threads will get 0 as the mask…
Furthermore, AFAICS, the above logic is redundant with what the kernel
does anyway. That is, in a single-threaded program,
mask = umask (0);
umask (mask);
mkdir (file, 0777 ^ mask);
is equivalent to:
mkdir (file, 0777);
Am I right that we should just remove these two ‘umask’ calls?
Ludo’.
PS: This code has been there since 1996 or earlier.
This bug report was last modified 8 years and 286 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.