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

primops: disallow readFile /dev/stdin #2720

Closed
wants to merge 2 commits into from
Closed

Conversation

LnL7
Copy link
Member

@LnL7 LnL7 commented Mar 11, 2019

Fixes #2716

@grahamc
Copy link
Member

grahamc commented Mar 11, 2019 via email

@LnL7
Copy link
Member Author

LnL7 commented Mar 11, 2019

If stdin is read more then once subsequent calls will return an empty string since it's consumed already.

@shlevy
Copy link
Member

shlevy commented Mar 12, 2019

@LnL7 The kosher thing to do here would be to have some state in the eval state to determine if stdin has been read and if so what its contents were.

@edolstra
Copy link
Member

IMHO this is a really bad idea, reading stdin is very impure and very non-compositional (for example, consider programs like nixos-rebuild or NixOps where an expression might be evaluated multiple times).

@edolstra
Copy link
Member

If the goal is to pass large strings, it might be better to add some flag for this, e.g. nix-instantiate --arg-from-file foobar /dev/stdin.

@LnL7
Copy link
Member Author

LnL7 commented Mar 12, 2019

I like the idea of --arg-from-file, do I change this to throw an error so it fails everywhere then?

@edolstra
Copy link
Member

@LnL7 Hm, I don't understand the question, what should throw an error?

@LnL7
Copy link
Member Author

LnL7 commented Mar 13, 2019

I made this to make the behaviour between darwin and linux consistent, so if we don't want this I would prefer to also disable the current behaviour on darwin.

@LnL7 LnL7 changed the title primops: add support for reading stdin primops: disallow readFile /dev/stdin Mar 19, 2019
@lheckemann
Copy link
Member

I'm not sure this would be sufficient, e.g. builtins.readFile /dev/fd/0 will still behave the same I presume. Perhaps checking the file type using fstat(0, &st) and only allowing regular files would be more appropriate.

@LnL7
Copy link
Member Author

LnL7 commented Mar 21, 2019

Hmm guess I didn't push my second commit, that's almost what I did 😄.

@lheckemann
Copy link
Member

Maybe it should use S_ISREG instead — I don't think we want to allow FIFOs either?

@LnL7 LnL7 force-pushed the read-stdin branch 2 times, most recently from c1db1b2 to e4233c6 Compare April 20, 2019 08:16
@LnL7
Copy link
Member Author

LnL7 commented Apr 20, 2019

Using S_ISREG doesn't work for symlinks without resolving them first so I extended the blacklist instead.

@lheckemann
Copy link
Member

Yes it does, as long as you use stat and not lstat.

@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

I closed this issue due to inactivity. → More info

@stale stale bot closed this Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

builtins.getFile /dev/stdin doesn't work on linux
5 participants