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

Fix r+ permission writeable check #77

Closed
wants to merge 2 commits into from
Closed

Conversation

yurganov
Copy link

@yurganov yurganov commented Aug 9, 2023

The r+ mode for opening a file is similar to r mode but has some added features. It opens the file in both read and write mode.

@@ -38,7 +38,7 @@ public function __construct(
}

$this->queue = new \SplQueue();
$this->writable = $this->mode[0] !== 'r';
$this->writable = $this->mode[0] !== 'r' || $this->mode == 'r+';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely needs normalization like in other places and can then just check for $this->mode !== 'r'?

See $mode = \str_replace(['b', 't', 'e'], '', $mode); in other places.

Copy link
Author

@yurganov yurganov Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function openFile(string $path, string $mode): File

https://github.com/danog/MadelineProto/blob/0689c16309a8a404f920f5e5543b64ad8a3309b2/src/MTProtoTools/FilesLogic.php#L360

The openFile is amphp function. Maybe I am wrong, but AS I can understand, IF it possible to create new file with amphp library with "r+" permission, so the library will do the rest -> create it, write it, ...

If I am wrong could you please explain to me why. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurganov I think you didn't understand correctly: The new check is better than the old one, but still potentially incorrect, e.g. for rb+ (at least I think that works). So it should normalize the mode with the mentioned function and then check just for !== 'r', as that's the only mode that is non-writable.

Copy link
Author

@yurganov yurganov Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kelunik, absolutely, I overlooked the 'rb' option. I believe it's simpler to validate only for 'r' and 'rb. Please check my commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurganov I still think we should remove b, t, and e from the mode, as they're just flags and that can be present in any order IIRC.

@trowski trowski closed this in 45d8d84 Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants