git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] be paranoid about closed stdin/stdout/stderr

From
KCKarl Chen <quarl@cs.berkeley.edu>
Date
Aug 27, 2008, 03:05 UTC
Message-ID
<quack.20080826T2005.lthzlmz2m4g@roar.cs.berkeley.edu>
In-Reply-To
<7v3akr2xa3.fsf@gitster.siamese.dyndns.org>
>>>>> On 2008-08-26 16:04 PDT, Junio C Hamano writes:
    Junio> I think
    Junio> 	$ git fetch 0<&-
    Junio> from the command line is a mere user stupidity.
    Junio> On the other hand, if a cron/at job that contains "git
    Junio> fetch" is launched in an environment with fd#0 (or #1
    Junio> or #2 for that matter) closed, it would certainly be
    Junio> problematic.  It can easily be worked around by
    Junio> redirecting file descriptors appropriately in the
    Junio> script that is launched, though.

I agree command-line 'git fetch 0<&-' is silly. The example I gave was minimized to show the symptom. I ran across this with a more complicated cron-ish setup that closes stdin. I actually had to look up the shell syntax for closing file descriptors.

Yes, I can work around this issue with sh -c 'git fetch 0</dev/null', and maybe it shouldn't close(0) in the first place. But I don't see the harm in being safe. It's one less potential surprise for users. This is the first program I've encountered that broke due to stdin being closed, and it took debugging to figure out that was the reason.

Re security, it's actually a good idea to be safe early on if it could ever become an issue. I keep /etc on my systems in version control, and I've worked in production environments where some users have access only via version control commands.

Previous: Stephen R. van den BergNext: Paolo Bonzini
Message 31 of 37 in “Fix start_command() pipe bug when stdin is closed.”
  1. Fix start_command() pipe bug when stdin is closed.Karl Chen, Aug 25, 2008
  2. Johannes SixtAug 25, 2008
  3. Paolo BonziniAug 25, 2008
  4. fix start_command() bug when stdin is closedPaolo Bonzini, Aug 25, 2008
  5. Johannes SixtAug 25, 2008
  6. fix start_command() bug when stdin is closedPaolo Bonzini, Aug 25, 2008
  7. Karl ChenAug 25, 2008
  8. Junio C HamanoAug 26, 2008
  9. Junio C HamanoAug 26, 2008
  10. Johannes SixtAug 26, 2008
  11. Paolo BonziniAug 26, 2008
  12. be paranoid about closed stdin/stdout/stderrPaolo Bonzini, Aug 26, 2008
  13. Johannes SixtAug 26, 2008
  14. Stephen R. van den BergAug 26, 2008
  15. Avery PennarunAug 27, 2008
  16. Stephen R. van den BergAug 27, 2008
  17. Paolo BonziniAug 27, 2008
  18. make git-shell paranoid about closed stdin/stdout/stderrPaolo Bonzini, Aug 27, 2008
  19. Stephen R. van den BergAug 27, 2008
  20. Junio C HamanoAug 27, 2008
  21. Paolo BonziniAug 28, 2008
  22. Stephen R. van den BergAug 28, 2008
  23. Avery PennarunAug 27, 2008
  24. Nick AndrewAug 28, 2008
  25. Stephen R. van den BergAug 28, 2008
  26. Junio C HamanoAug 26, 2008
  27. Paolo BonziniAug 26, 2008
  28. Junio C HamanoAug 26, 2008
  29. Junio C HamanoAug 26, 2008
  30. Stephen R. van den BergAug 26, 2008
  31. Karl ChenAug 27, 2008
  32. Paolo BonziniAug 27, 2008
  33. Stephen R. van den BergAug 27, 2008
  34. Johannes SixtAug 27, 2008
  35. Paolo BonziniAug 27, 2008
  36. Nick AndrewAug 27, 2008
  37. Karl ChenAug 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.