Skip to content

don't use system to open files - #156

Closed
miDeb wants to merge 1 commit into
crazecoder:masterfrom
miDeb:no_system
Closed

don't use system to open files#156
miDeb wants to merge 1 commit into
crazecoder:masterfrom
miDeb:no_system

Conversation

@miDeb

@miDeb miDeb commented Jul 18, 2021

Copy link
Copy Markdown

This removes the ability to use system to open files. Instead we use Process.runSync.

Quoting the manpage for system:

Any user input that is employed as part of command should be carefully sanitized,
to ensure that unexpected shell commands or command options are not executed.

AFAICT only spaces are replaced with \ right now. This is not enough, and invoking the
system function is also completely unnecessary. Creating a new process directly is both
simpler and better. This option was introduced in #127,
however only on linux and not as the default. This is not sufficient.

Without this PR, running the following in an unsandboxed flutter app on linux would open gnome-calculator
(if installed, but you can place any command in there that will be executed):

  OpenFile.open(";gnome-calculator");

I haven't tested this on macOS but it should work there similarly to linux.

@mx1up

mx1up commented Jul 22, 2021

Copy link
Copy Markdown
Contributor

@prateekmedia

prateekmedia commented Sep 21, 2021

Copy link
Copy Markdown

Hi, nice PR but when I tried to open a music file using this then it made my application hang on linux until I close my music player.

The solution can be to run this command asynchronously

This removes the ability to use `system` to open files. Instead we use `Process.runSync`.

Quoting the [manpage for `system`](https://man.archlinux.org/man/system.3):
> Any user input that is employed as part of command should be carefully sanitized,
> to ensure that unexpected shell commands or command options are not executed.

AFAICT only spaces are replaced with `\ ` right now. This is not enough, and invoking the
`system` function is also completely unnecessary. Creating a new process directly is both
simpler and better. This option was introduced in crazecoder#127,
however only on linux and not as the default. This is not sufficient.

Running the following in an unsandboxed flutter app on linux would open `gnome-calculator`
(if installed, but you can place any command in there that will be executed):
```dart
  OpenFile.open(";gnome-calculator");
```

I haven't tested this on macOS but it _should_ work there similarly to linux.
@miDeb

miDeb commented Sep 21, 2021

Copy link
Copy Markdown
Author

Thanks for pointing this out, it should be fixed now.

@prateekmedia

Copy link
Copy Markdown

@crazecoder Any status on this PR?

@javaherisaber

Copy link
Copy Markdown

@prateekmedia @miDeb
Your change does not seem to be working with a simple scenario like this:

OpenFile.open('~/Downloads/flutter.png');

Tested on Linux (Ubuntu)

@miDeb

miDeb commented Dec 31, 2023

Copy link
Copy Markdown
Author

@javaherisaber your "simple use case" requires a shell to expand the path ~. My change however removed the execution through the shell, therefore no shell expansion is happening and you can only open relative or absolute paths. At least that's what I think is happening.

@javaherisaber

Copy link
Copy Markdown

@miDeb
I don't know much about Linux terminologies, but wouldn't it be a use-case for other users that rely on shell?
Can you share some of your usecases?

@miDeb

miDeb commented Dec 31, 2023

Copy link
Copy Markdown
Author

I would argue this package's job is to open the file that is located at the path specified, not necessarily to modify the path by performing shell expansion (e.g. expanding ~ to the user's home directory)

@prateekmedia

Copy link
Copy Markdown

@miDeb is right, this package will only be used when the file path is known either relative or absolute, in both the cases we will have the correct path and not the path with ~ instead of home directory.

@crazecoder crazecoder closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants