MyBB Community Forums

Full Version: [F] Avatar wrong CHMod
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Wow, that's really really stupid. They actually make you quote it?

wow...
(2008-08-09, 06:09 AM)Tikitiki Wrote: [ -> ]
if(substr((string)$mode, 0, 1) != '0' || strlen((string)$mode) !== 4)

Thanks, now it works Smile
Michael, any reason why it works for Dyers Eve and not you?
I'm sorry, i checked these files today again and I found out, why I thought that this fix works.

I changed in functions_upload.php
@my_chmod($path."/".$filename, 0644, '0644');

and in functions.php
function my_chmod($file,$mode,$mymode)
{
	if(substr($mymode, 0, 1) != '0' || strlen($mymode) !== 4)
	{
		return false;
	}
	$old_umask = umask(0);
	$result = chmod($file, $mode);
	umask($old_umask);
	return $result;
}

These modification works. After that, I read the post from Ryan and changed only function_upload.php and in functions.php the function-head and forgot to change the variable name in the if clause

function my_chmod($file,$mode)
{
	if(substr((string)$mymode, 0, 1) != '0' || strlen((string)$mymode) !== 4)
	{
		return false;
	}
	$old_umask = umask(0);
	$result = chmod($file, $mode);
	umask($old_umask);
	return $result;
}

...but as everybody can see, this is silly.

But I don't know why
(string)$mode != '0644'

Greetings, Dyers Eve
OK, now i know what happened

0644 is octal and php change this.

echo string($mode) returns 420
echo decoct($mode) returns 644
This would be my solution for that problem:

function_upload.php
@my_chmod($path."/".$filename, '0644');

functions.php

function my_chmod($file,$mode)
{
	if(substr($mode, 0, 1) != '0' || strlen($mode) !== 4)
	{
		return false;
	}
	$old_umask = umask(0);
	$result = chmod($file, octdec($mode));
	umask($old_umask);
	return $result;
}

Greetings, Dyers Eve
Dyers Eve, Does this fix simply work?

function my_chmod($file, $mode)
{
	if(substr("{$mode}", 0, 1) != '0' || strlen("{$mode}") !== 4)
	{
		return false;
	}
	$old_umask = umask(0);
	$result = chmod($file, $mode);
	umask($old_umask);
	return $result;
}
No, chmod is still 600

echo "{$mode}";
-> 420
Hmm okay, so I see how your fix works. And it should work properly too.
When I change the test script to your latest version it still outputs "Failure!".
<?php
function my_chmod($mode)
{
	//$mode = (string) $mode;
    if(substr("{$mode}", 0, 1) != '0' || strlen("{$mode}") !== 4)
    {
        echo "Failure!";
    }
    else
    {
        echo "Success";
    }
}

my_chmod(0644);
?>
Pages: 1 2