-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: TempDir() returns path without validation #19695
Comments
This is more or less a dup of #12823 (vague error when TMPDIR is set to directory that doesn't exist). It looks like the consensus was that it's not worth doing any validation work on the
|
I appreciate the quick response. :) I feel that there are bad assumptions being made about I also don't understand the aversion to checking, what is user input, I appreciate your time, however, if you still feel that it's not worth the work, close this issue as "unfortunate" as well. |
I don't have strong feelings about this (I linked the past discussion just for reference); so I'm not closing this; maybe it would be acceptable to at least validate Labelling as needing-decision. |
Tempdir cannot change signature without breaking the Go 1 compatibility guidelines, so there is no clean way to fix this, if indeed it is a problem. Leaving open for now in case anyone has insight, but I think this is just unfortunate. Don't set your TMPDIR do a nonsense value. |
Look at it this way: the code that's calling |
As Rob said, we can't change the signature. We could update the docs to warn that the directory may not exist, but they're already pretty good:
(It says "default" at least, hinting perhaps that it's a conventional value being returned and not something guaranteed? But kind of a stretch.) We could add "It is not guaranteed to exist if the person running the program did something weird." but if you put warning labels on everything, people start to glaze over them. Maybe just: "The directory may not exist." Or.... we document exactly what the function does. That it returns the value of $TMPDIR if non-empty in the environment, otherwise returns the conventional path based on the operating system. On Windows we use GetTempPath (https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx) which has the same behavior. ("Note that the function does not verify that the path exists, nor does it test to see if the current process has any kind of access rights to the path.") I'll mark this as a documentation issue. |
CL https://golang.org/cl/45702 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
Used
os.TempDir()
in a project.To reproduce:
os.TempDir()
os.TempDir()
for filesystem operations.What did you expect to see?
os.TempDir()
to return an error that the path doesn't exist.What did you see instead?
os.TempDir()
passing back a string without validation that the path exists viaStat()
Proposed patch:
The text was updated successfully, but these errors were encountered: