Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Check exec and stat method before using it #30546

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,26 @@ public function filemtime($path) {
return false;
}
if (PHP_INT_SIZE === 4) {
if (\OC_Util::runningOn('linux')) {
return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath));
} else if (\OC_Util::runningOn('bsd') || \OC_Util::runningOn('mac')) {
return (int) exec ('stat -f %m '. escapeshellarg ($fullPath));
/**
* Check if exec is available to use before calling it.
*/
if (function_exists('exec') === true) {
$result = 0;
$returnVar = 0;
if (\OC_Util::runningOn('linux')) {
$result = (int)exec('stat -c %Y ' . escapeshellarg($fullPath), $output, $returnVar);
} else if (\OC_Util::runningOn('bsd') || \OC_Util::runningOn('mac')) {
$result = (int)exec('stat -f %m ' . escapeshellarg($fullPath), $output, $returnVar);
}

/**
* If the result is zero, then stat is missing.
* Additionally check the return status from the shell.
*/
if ($returnVar === 0) {
return $result;
}
}
return false;
}
return filemtime($fullPath);
}
Expand Down