godot/drivers
Max Hilbrunner be6712fb3d
Fix Windows platform file access
This restores Windows platform file handling back to open files non-exlusively by default, as was the case before October 2018. (See b902a2f2a7)
Back then, while fixing warnings for MSVC, the function used for opening files was changed from _wfopen() to _wfopen_s() as suggsted by the warning C4996. ("This function may be unsafe, consider using _wfopen_s instead.")

This new function
1. did parameter validation and thus avoided some possible security issues due to nil pointers or wrongly terminated strings
2. it also changed the default file sharing for opened files from _SH_DENYNO (which was the implicit default for the previous _wfopen()) to _SH_SECURE.

_SH_DENYNO means every opened file could be opened by other calls (like is the default on other operating systems).
_SH_SECURE means if the file is opened with READ access, others can still read the same file, but if it is opened with WRITE access, others can't open it at all, not even to read.

This led to rarely occuring bugs on Windows, i.e. due to random access by Antivirus processes, or Godot/Windows not closing a file handle fast enough while trying to open it again elsewhere (i.e. project.godot, instead showing the Project manager, or saving shaders/debugging the game).

What this PR does it change the file access to a third method, _wfsopen(). This is still secure, doing parameter validation and thus avoids the warning, but it allows us to actually SET the file sharing parameter. And we set it to _SH_DENYNO, as it was implicitely before the change. (And as it currently is on all non-Windows platforms, where file sharing restrictions don't exist by default.)

Warning C4996 should really have been pointing this out. It should've been _wfsopen() all along. Let's hope this banishes those annoying, rare errors for all eternity.

Fixes #28036.

(cherry picked from commit b48cbb5da9)
2021-08-13 10:37:26 +02:00
..
alsa Omit some functions in alsa wrapper 2021-02-22 21:39:22 +01:00
alsamidi Modernize Thread 2021-02-18 11:58:08 +01:00
coreaudio Replace malloc's with Godot's memalloc macro 2021-03-13 22:01:27 +01:00
coremidi Update copyright statements to 2021 2021-01-13 16:17:06 +01:00
dummy Clear glErrors instead of crashing when initializing GLES3 2021-06-29 13:53:07 +02:00
gl_context SCons: Add explicit dependencies on thirdparty code in cloned env 2021-05-04 12:54:34 +02:00
gles2 Clear glErrors instead of crashing when initializing GLES3 2021-06-29 13:53:07 +02:00
gles3 Clear glErrors instead of crashing when initializing GLES3 2021-06-29 13:53:07 +02:00
gles_common Batching - fix item_batch_flags stale state 2021-05-24 12:58:59 +02:00
png SCons: Add explicit dependencies on thirdparty code in cloned env 2021-05-04 12:54:34 +02:00
pulseaudio Fix crash when using ALSA MIDI with PulseAudio 2021-06-03 12:41:29 +02:00
unix FileAccess: Don't err in store_buffer with buffer of size 0 2021-06-07 22:56:01 +02:00
wasapi Modernize Thread 2021-02-18 11:58:08 +01:00
windows Fix Windows platform file access 2021-08-13 10:37:26 +02:00
winmidi Update copyright statements to 2021 2021-01-13 16:17:06 +01:00
xaudio2 Modernize Thread 2021-02-18 11:58:08 +01:00
register_driver_types.cpp Update copyright statements to 2021 2021-01-13 16:17:06 +01:00
register_driver_types.h Update copyright statements to 2021 2021-01-13 16:17:06 +01:00
SCsub Unified GLES2 / GLES3 Batching 2020-10-16 10:34:47 +01:00