-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SDL_filesystem: get temporary folder #10841
Comments
I planned to keep SDL_Folder and SDL_GetUserFolder for folders that are managed by the user and whose path depend on the users' preferences and other settings; I describe it with more detail in #9538 (comment), #8051 and #7665 (comment). In short: I wanted to "do one thing and do it well". The function is meant to return folders that are under the user's control like "My Stuff", and I preferred to keep folders that would need further OS- or app-dependant treatment (like I'd support adding other OS-specific folders, but I would encourage writing their own functions for them, since each of them would need some special functionality and may require additional parameters (Trash folder needs to remember the files' original locations, mktemp has code to generate a safe temp folder, etc). Assuming we decide to stick to my vision of things, @slouken should I rename the SDL_Folder enum to SDL_UserFolder? |
My current use case for getting a temporary path is for testing redirection of process stdin/stdout/stderr to/from a file. |
Should an eventual SDL_CreateTempFile/Folder return a path or an IOStream object? The latter would reduce the chances of timing attacks in cases where the contents of the temp file are sensitive. |
It should return an IOStream object, though we should probably add a file path property. |
I believe I read that some systems can create temporary files that don't have path equivalents, only file descriptors, but now I can't find those functions anymore so I'm not sure if it's relevant to mention them. |
I think you're thinking of mkstemp: |
mkstemp creates a file that has a path equivalent, which is formatted according to its only argument (most commonly something like |
Ah, gotcha. |
After some more research, it appears that No matter what terms I search for, I cannot find anything about such a function. If I trust my usual luck, I will find nothing, start thinking I've hallucinated that function, and give up, and the moment the API is settled on beyond any further modification, I'll finally find it. |
You might be thinking of |
There's also |
At least on Unix, the problem with using paths for temporary files is usually not "other processes might read its contents". If the attacker is the same uid and non-sandboxed, then you've already lost because they can read your memory contents via debugging interfaces, and if the attacker is a different uid, permissions are enough to protect you (any reasonable temporary file API will either default to 600/700 permissions or require the mode as a parameter, for this reason). Instead, the classic problem with using paths for temporary files is "the attacker might trick you into overwriting some unrelated file". See also #11887, https://en.wikipedia.org/wiki/Symlink_race and https://capec.mitre.org/data/definitions/27.html. https://security.opensuse.org/2023/12/14/budgie-extras-predictable-tmp-paths.html is a typical real-world example. (I don't know what the security model is on Windows, things might be different there.) |
In the absence of system-specific facilities like Linux memfds and The ability to unlink a file while keeping it opened is a POSIX thing, and I'm not sure it's possible on Windows. |
Would it make sense to get the system-dependent temporary folder using the SDL_filesystem api?
Or do we then also need to think about the bigger picture, and provide SDL alternatives of
mkstemp
and family?These folder categories currently exist:
SDL/include/SDL3/SDL_filesystem.h
Lines 166 to 192 in 16ff750
The text was updated successfully, but these errors were encountered: