ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: ahrasis on March 04, 2018, 09:31:50 pm

Title: Check all files against current versions error
Post by: ahrasis on March 04, 2018, 09:31:50 pm
Can anybody running EA 1.1.2 test this (especially with nginx + php7 like me)? Admin > Maintenance > Routine > Check all files against current versions > Run task now

I kinda got an error but will need confirmation from others before reporting.
Title: Re: Check all files against current versions error
Post by: ahrasis on March 04, 2018, 09:46:27 pm
It doesn't seems to be the problem with the 1.1.2 update. I will carry on inspecting. Meanwhile, I do appreciate any feedback from others.
Title: Re: Check all files against current versions error
Post by: badmonkey on March 04, 2018, 10:19:49 pm
I'm getting an open basedir restriction error.  Which is puzzling.... :-X
Title: Re: Check all files against current versions error
Post by: ahrasis on March 04, 2018, 10:31:37 pm
Ok. That is the same with me @badmonkey (we both use ISPConfig).

The error:
QuoteSplFileInfo::isDir(): open_basedir restriction in effect. File(/var/www/clients/client2/web1/web/..) is not within the allowed path(s):

The ".." is not a file at all. The line complained is "if ($dir->isDir())" of which "$dir" revert back to "$iter" in the function below:
Code: [Select]
function readFileVersions(&$version_info, $directories, $pattern, $recursive = false)
{
// The comment looks roughly like... that.
$version_regex = '~\*\s@version\s+(.+)[\s]{2}~i';
$unknown_version = '??';

$ext_offset = -strlen($pattern);

foreach ($directories as $type => $dirname)
{
if ($recursive === true)
{
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);
}
else
{
$iter = new IteratorIterator(new DirectoryIterator($dirname));
}

foreach ($iter as $dir)
{
if ($dir->isDir())
{
continue;
}
$entry = $dir->getFilename();

if (substr($entry, $ext_offset) == $pattern)
{
if ($dir->isWritable() === false)
{
continue;
}
// Read the first 768 bytes from the file.... enough for the header.
$header = file_get_contents($dir->getPathname(), false, null, 0, 768);

if ($recursive === true)
{
$entry_key = $dir->getPathname();
}
else
{
$entry_key = $entry;
}

// Look for the version comment in the file header.
if (preg_match($version_regex, $header, $match) == 1)
$version_info[$type][$entry_key] = $match[1];
// It wasn't found, but the file was... show a $unknown_version.
else
$version_info[$type][$entry_key] = $unknown_version;
}
}
}
}

I think, somehow, "$iter" also catches ".." as file which it should not. The php coding is an advanced one (to me), so I am not quite sure I understand correctly nor I am able to help on determining the true error or fixing this one.

I hope @emanule can look into it.
Title: Re: Check all files against current versions error
Post by: badmonkey on March 04, 2018, 11:01:29 pm
Yeah, kind of wondered if that was the same error you were getting. 

For sake of full disclosure, nginx 1.13.9, php 7.2.2, mariadb 10.2.13. It's probably irrelevant, but just in case.  8)
Title: Re: Check all files against current versions error
Post by: ahrasis on March 04, 2018, 11:17:22 pm
Linux kernel 4.15.7, Nginx 1.13.8, Php 7.2.2, MariaDB 10.2.13 ;)
Title: Re: Check all files against current versions error
Post by: ahrasis on March 05, 2018, 12:19:41 am
Could it be because we are using "DirectoryIterator" instead of "FilesystemIterator" where the former may use "." and ".." ([1]). I tested with the later and it works without error but I need confirmation.

The original code:
Code: [Select]
			$iter = new IteratorIterator(new DirectoryIterator($dirname));

The fixed code?:
Code: [Select]
			$iter = new IteratorIterator(new FilesystemIterator($dirname));

Is this the right way to fix it @emanuele?

Edited: I opened this as an issue and PR the above as suggested fix, so time will not be wasted if it is acceptable as a fix.
Based on my readings at: https://stackoverflow.com/questions/12532064/difference-between-directoryiterator-and-filesystemiterator
Title: Re: Check all files against current versions error
Post by: radu81 on March 05, 2018, 02:45:36 am
works fine for me  ;)

if can be useful test.sss.ovh/skoda/phpinfo_.php
Title: Re: Check all files against current versions error
Post by: ahrasis on March 05, 2018, 06:08:01 am
That is because your open_basedir has no value, which is not safe / advisable. Mine (and probably @badmonkey too) has value to it.

Quote/var/www/clients/client2/web1/web:/var/www/clients/client2/web1/private:/var/www/clients/client2/web1/tmp:/var/www/elkarte.sch.my/web:/srv/www/elkarte.sch.my/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/dev/random:/dev/urandom
Title: Re: Check all files against current versions error
Post by: badmonkey on March 05, 2018, 09:48:21 pm
Confirmed it works without the error, and without errors in the forum error log.   8)  Nice work @ahrasis‍ 
Title: Re: Check all files against current versions error
Post by: emanuele on March 06, 2018, 11:48:25 am
I guess so @ahrasis Iterator are still a bit a mystery for me. :P
Title: Re: Check all files against current versions error
Post by: ahrasis on March 06, 2018, 09:33:01 pm
For me all codes are always mysterious... :P
Title: Re: Check all files against current versions error
Post by: emanuele on March 07, 2018, 02:28:02 am
LOL
Title: Re: Check all files against current versions error
Post by: ahrasis on April 28, 2018, 10:51:03 pm
Just to note that this is somehow missed in 1.1.3 package. I think issue number was #3120 but I will create a new PR anyway.
Title: Re: Check all files against current versions error
Post by: emanuele on April 29, 2018, 04:07:34 pm
O:-)
Title: Re: Check all files against current versions error
Post by: ahrasis on October 27, 2018, 10:34:44 am
I noted that @emanuele reverted the iterator to the old one in EA 1.1.5 causing the same error all over again. Please refix in 1.1.6 and note that I won't be re-opening the same issue again at github.
Title: Re: Check all files against current versions error
Post by: emanuele on October 27, 2018, 11:39:15 am
@ahrasis you sent the pull request to development, not to the patch version, I didn't notice and the fix was missed.

https://github.com/elkarte/Elkarte/pull/3166
Title: Re: Check all files against current versions error
Post by: ahrasis on October 28, 2018, 08:53:10 am
Sorry but I only know as there are only development, master and gh-pages branches; and I am not sure how to PR to other than that. I remember that I was told that PR to development should be fine?

This 1.1.2 fix was already noted by you and @Spuds in PR #3121 and #3166, for milestone 1.1.3 and 1.1.4, and I only come to know it is not there again when I updated to 1.1.5 as I haven't updated to 1.1.4; so I don't have clue if somebody will forget about it again in any update?

I guess I'll post and remind here (forum instead of github) in the future.
Title: Re: Check all files against current versions error
Post by: tino on October 28, 2018, 09:17:24 am
@emanuele  If you create the 1.1.6 branch I will do that change against that. Same as the other outstanding one I currently have on there that I can't switch to the new branch as it doesn't exist.

That ok with you @ahrasis ?
Title: Re: Check all files against current versions error
Post by: emanuele on October 28, 2018, 03:51:02 pm
Oh my... I forgot to create the branch, sorry!! :-[
Now it's up.