gitk: Add ability to define an alternate temporary directory
PATCH 1/1 gitk: Add ability to define an alternate temporary directory
gitk fails to show diffs when browsing a repository for which we have read-only access. This is due to gitk's assumption that the current directory is always writable.
This teaches gitk to honor the GITK_TMPDIR environment variable. This allows users to override the default location used for writing temporary files.
--- gitk | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
gitk +7 -3
@@ -3170,11 +3170,15 @@ proc flist_hl {only} { } proc gitknewtmpdir {} { - global diffnum gitktmpdir gitdir + global diffnum env gitktmpdir gitdir if {![info exists gitktmpdir]} { - set gitktmpdir [file join [file dirname $gitdir] \ - [format ".gitk-tmp.%s" [pid]]] + if {[info exists env(GITK_TMPDIR)]} { + set tmpdir $env(GITK_TMPDIR) + } else { + set tmpdir [file dirname $gitdir] + } + set gitktmpdir [file join $tmpdir [format ".gitk-tmp.%s" [pid]]] if {[catch {file mkdir $gitktmpdir} err]} { error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" unset gitktmpdir
Signature · 1 line
1.6.5.2.180.gc5b3e
PATCH 1/1 gitk: Document the $GITK_TMPDIR variable
--- Documentation/gitk.txt | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
Documentation/gitk.txt +5 -0
@@ -100,6 +100,11 @@ Files Gitk creates the .gitk file in your $HOME directory to store preferences such as display options, font, and colors. +Environment Variables +--------------------- +Gitk honors the $GITK_TMPDIR environment when creating temporary +files and directories. + SEE ALSO -------- 'qgit(1)'::
Signature · 1 line
1.6.5.2.180.gc5b3e
Quoted 8 lines · David Aguilar
gitk fails to show diffs when browsing a repository for which we have read-only access. This is due to gitk's assumption that the current directory is always writable.
This teaches gitk to honor the
GITK_TMPDIRenvironment variable. This allows users to override the default location used for writing temporary files.
Is there a good reason not to use the common TMPDIR or TMP environment variables for this?
Sam
Quoted 5 lines · Sam Vilain
Quoted 4 lines · David Aguilar
gitk fails to show diffs when browsing a repository for which we have read-only access. This is due to gitk's assumption that the current directory is always writable.
Quoted 7 lines
Quoted 4 lines
This teaches gitk to honor the
GITK_TMPDIRenvironment variable. This allows users to override the default location used for writing temporary files.Is there a good reason not to use the common TMPDIR or TMP environment variables for this?
I, personally, would not be opposed to that.
The only reason I chose a different variable was that I didn't want to change the existing behavior (backwards-compat hat on).
Since TMPDIR and TMP are common then we'd be changing the behavior.
That said, if there's a consensus that the path doesn't matter much than we could change the behavior. I was just trying to be careful.
Signature · 1 line
David
Quoted 3 lines · David Aguilar
That said, if there's a consensus that the path doesn't matter much than we could change the behavior. I was just trying to be careful.
If we are not honoring GITK_TMPDIR and suddenly start paying attention to it, that already is a change in behaviour. Why is it better than paying attention to TMPDIR?
But why does gitk, which is primarily a read-only history browsing tool (yes, I know it can do "checkout" and stuff), needs to write anything to anywhere in the first place?
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · David Aguilar
That said, if there's a consensus that the path doesn't matter much than we could change the behavior. I was just trying to be careful.
If we are not honoring
GITK_TMPDIRand suddenly start paying attention to it, that already is a change in behaviour. Why is it better than paying attention to TMPDIR?
True.
Quoted 3 lines
But why does gitk, which is primarily a read-only history browsing tool (yes, I know it can do "checkout" and stuff), needs to write anything to anywhere in the first place?
It happens when you click on a commit, right-click on a file and then choose "external diff".
gitk writes file@commit and file@commit^ to temporary files and diffs them using an external diff tool.
Shall I reroll with s/GITK_TMPDIR/TMPDIR/ ?
gitk was written before git-difftool existed.
A higher impact change would be to change gitk to use git-difftool instead of managing its own temporary files.
If we're looking for the ideal solution than that is probably it. The only downside is that gitk would stop working with git versions < 1.6.3. That doesn't seem like a real issue, though, because gitk is bundled with git.
Thoughts?
Signature · 1 line
David
Quoted 4 lines · David Aguilar
gitk writes file@commit and file@commit^ to temporary files and diffs them using an external diff tool.
Shall I reroll with s/GITK_TMPDIR/TMPDIR/ ?
gitk seems to use a very predictable temp filename (".gitk-tmp.$PID"). Have you checked that you are not introducing any security holes by creating that predictable filename in a publicly writable tmpdir?
It looks like it always tries to "mkdir" the file. Does tcl's mkdir function barf on an existing directory? If so, then I think we may be safe from the naive:
tmp=.gitk-tmp.pidof_other_users_gitk
mkdir $tmp
ln -s /file/for/other/user/to/destroy /tmp/1
attack. And I think we are not susceptible to races because we fail if the mkdir fails (instead of doing something stupid like stat followed by mkdir).
But it has been a long time since I thought about /tmp security, so I may be forgetting something.
-Peff
Quoted 19 lines · Jeff King
Quoted 4 lines · David Aguilar
gitk writes file@commit and file@commit^ to temporary files and diffs them using an external diff tool.
Shall I reroll with s/GITK_TMPDIR/TMPDIR/ ?
gitk seems to use a very predictable temp filename (".gitk-tmp.$PID"). Have you checked that you are not introducing any security holes by creating that predictable filename in a publicly writable tmpdir?
It looks like it always tries to "mkdir" the file. Does tcl's mkdir function barf on an existing directory? If so, then I think we may be safe from the naive:
tmp=.gitk-tmp.
pidof_other_users_gitk
mkdir $tmp
ln -s /file/for/other/user/to/destroy/tmp/1
Quoted 8 lines
attack. And I think we are not susceptible to races because we fail if the mkdir fails (instead of doing something stupid like stat followed by mkdir).
But it has been a long time since I thought about /tmp security, so I may be forgetting something.
-Peff
Thanks for the review.
I'm about to reroll with a new subject, "gitk: Honor TMPDIR..."
When I have more time I can switch gitk over to git-difftool which I know is /tmp safe. I only dabble in tcl but the docs say that mkdir does not error out when given directories that already exist. It does error out when given a file.
The /tmp trick would require them knowing the SHA-1 that we're diffing and symlinking the names to paths they want us to destroy. It seems paranoid to worry about it ;) but since if it's a real concern than I'll try to get to the git-difftool rework within the next two week. I only dabble in tcl ;)
Signature · 1 line
David
Quoted 5 lines · David Aguilar
When I have more time I can switch gitk over to git-difftool which I know is /tmp safe. I only dabble in tcl but the docs say that mkdir does not error out when given directories that already exist. It does error out when given a file.
OK, then I think we would be vulnerable, as I can make a .gitk-tmp.$PID directory owned by me that your gitk will happily use.
Quoted 3 lines
The /tmp trick would require them knowing the SHA-1 that we're diffing and symlinking the names to paths they want us to destroy. It seems paranoid to worry about it ;)
But the SHA-1 is not hard to guess[1], as you have a finite, easily-enumerable list of them in your repository. :) One thing that does make it harder is that gitk actually checks to see if a file is already there before creating it (presumably not for security, but for efficiency). Which means I can't just pre-seed a trap and wait for you to run gitk; I have to actually race you and create the file between your "file exists" check and the eventual "git show $filename >$output" which will hose it.
Probably I can win that race given a sufficient number of attempts, but attempts are made at a human pace. So in practice it's probably pretty hard to exploit. Still, I'd rather see it done properly on principle. Then we _know_ we're not missing some trick, and there's no chance of a later code change increasing an attacker's probability of success.
-Peff
[1] I was also going to suggest a social-engineering attack, like "hey, I screwed up my repository. Can you take a look?" Then you don't need to guess the SHA-1, as you convince the victim to look at a specific one. But that attack is already much, much worse: we respect items in .git/config regardless of whether it is owned by the running user. So it is not actually safe to "cd ~other_user/project && git diff".