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

[stable30] Fix remaining readdir() calls in loops with undesirable false evaluation potential #49241

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
}

$dh = $this->opendir($path);
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 1 of readdir cannot be false, possibly resource value expected
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
continue;
}
Expand Down Expand Up @@ -494,7 +494,7 @@
}

$dh = $this->opendir($source);
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 1 of readdir cannot be false, possibly resource value expected
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ private static function getTrashbinSize(string $user): int|float {
public static function isEmpty($user) {
$view = new View('/' . $user . '/files_trashbin');
if ($view->is_dir('/files') && $dh = $view->opendir('/files')) {
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if (!Filesystem::isIgnoredDir($file)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function copy($source, $target) {
$this->remove($target);
$dir = $this->opendir($source);
$this->mkdir($target);
while ($file = readdir($dir)) {
while (($file = readdir($dir)) !== false) {
if (!Filesystem::isIgnoredDir($file)) {
if (!$this->copy($source . '/' . $file, $target . '/' . $file)) {
closedir($dir);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/PolyFill/CopyDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function copy($source, $target) {
protected function copyRecursive($source, $target) {
$dh = $this->opendir($source);
$result = true;
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($this->is_dir($source . '/' . $file)) {
$this->mkdir($target . '/' . $file);
Expand Down
2 changes: 1 addition & 1 deletion tests/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function loadDirectory($path): void {
return;
}

while ($name = readdir($dh)) {
while (($name = readdir($dh)) !== false) {
if ($name[0] === '.') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testDirectories($directory) {

$dh = $this->instance->opendir('/');
$content = [];
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testDirectories($directory) {

$dh = $this->instance->opendir('/');
$content = [];
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/Storage/Wrapper/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function testNormalizedDirectoryEntriesOpenDir() {

$dh = $this->instance->opendir('/test');
$content = [];
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Files/Storage/Wrapper/JailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function tearDown(): void {
// test that nothing outside our jail is touched
$contents = [];
$dh = $this->sourceStorage->opendir('');
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$contents[] = $file;
}
Expand Down
Loading