php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76698 mkdir doesn't handle group write permission with 0770 mode
Submitted: 2018-08-03 10:20 UTC Modified: 2018-08-03 14:02 UTC
From: zoeslam at gmail dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 7.2.8 OS: Debian Stretch
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zoeslam at gmail dot com
New email:
PHP Version: OS:

 

 [2018-08-03 10:20 UTC] zoeslam at gmail dot com
Description:
------------
mkdir($dir, 0770) skips group write permission

https://3v4l.org/pKu4U

Test script:
---------------
$dir = uniqid('/tmp/test_0700_');
mkdir($dir, 0700);
$fileperms = 0777 & fileperms($dir);
var_dump(0700 === $fileperms);
var_dump(decoct($fileperms));

$dir = uniqid('/tmp/test_0770_');
mkdir($dir, 0770);
$fileperms = 0777 & fileperms($dir);
var_dump(0770 === $fileperms);
var_dump(decoct($fileperms));

Expected result:
----------------
bool(true)
string(3) "700"
bool(true)
string(3) "770"

Actual result:
--------------
bool(true)
string(3) "700"
bool(false)
string(3) "750"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-03 10:33 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-08-03 10:33 UTC] requinix@php.net
What's your umask?
 [2018-08-03 11:44 UTC] spam2 at rhsoft dot net
the umask is for control default permission while the topic is explicit one!

mkdir also has a problem with permissions when create a recursive directory tree
 [2018-08-03 11:48 UTC] requinix@php.net
> the umask is for control default permission
No, it applies to default and explicit values. Read the docs.
 [2018-08-03 11:54 UTC] spam2 at rhsoft dot net
wrong behavior doesn't get better by nosense in docs
when i say 0770 i mean 0770, full stop

if i need to fire up a chmod after mkdir to have a conrtolled behavior please remove that idiotic parameter entirely so people are awarw - hopefully next you don't tell me chmod() has also ramndom behavior

frankly the whole point for the chmod param is that in case of umasks you you can make sure that your script set what you say nd not relies on arbitary local defaults
 [2018-08-03 12:10 UTC] zoeslam at gmail dot com
Indeed, I have to say to myself RTFM about the mode argument:

https://secure.php.net/manual/en/function.mkdir.php

This can be closed.
 [2018-08-03 12:15 UTC] spam2 at rhsoft dot net
> Indeed, I have to say to myself RTFM about the mode argument:
> https://secure.php.net/manual/en/function.mkdir.php

NO jesus

"The mode is also modified by the current umask, which you can change using umask()" tlaking about anything else then DEFAULTS makes no sense

the whole problem likely is that it *has any default* instead just let the OS act on it's defaults based on the umask and someone tried to coide fuzzy logik around that with the outcome we now have

if a function whcih get 0770 as chmod-param reulsts in anything else then 0770 this is a bug - full stop
 [2018-08-03 13:48 UTC] requinix@php.net
So you're saying PHP should pass the mode directly to the operating system, without doing anything regarding the umask?
 [2018-08-03 13:52 UTC] spam2 at rhsoft dot net
> So you're saying PHP should pass the mode directly to 
> the operating system, without doing anything regarding the umask?

exactly!

when i say "mode 0770" i mean exactly that
when i say nothing about mode i imean "use the current umask"
 [2018-08-03 14:02 UTC] requinix@php.net
Excellent. So we agree that PHP is behaving the way it's supposed to.

https://github.com/php/php-src/blob/PHP-7.2.8/Zend/zend_virtual_cwd.c#L1766
https://linux.die.net/man/2/mkdir

Next time, make sure you have your facts straight so you don't end up arguing against yourself.
 [2018-08-03 14:26 UTC] spam2 at rhsoft dot net
mkdir($dir, 0700);
should result in 700

mkdir($dir, 0770);
shoukd result in 770

full stop
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Nov 27 02:05:54 2022 UTC