* termio: new termio module
move the tcgetattr and tcsetattr functions in a new termio module.
The code needed refactoring as different OS have different fields
size, position and number for the C.termios structure, which
could not be correctly expressed consitently otherwise.
It has the positive side effect to reduce the number of unsafe calls.
New testing code was also added for the readline module as it is
relying of the feature.
* apply 2023 copyright to the new files too
os provides common OS/platform independent functions for accessing
command line arguments, reading/writing files, listing folders,
handling processes etc.
Security advice related to TOCTOU attacks
A few os module functions can lead to the TOCTOU vulnerability if used incorrectly.
TOCTOU (Time-of-Check-to-Time-of-Use problem) can occur when a file, folder or similar
is checked for certain specifications (e.g. read, write permissions) and a change is made
afterwards.
In the time between the initial check and the edit, an attacker can then cause damage.
The following example shows an attack strategy on the left and an improved variant on the right
so that TOCTOU is no longer possible.
ExampleHint: os.create() opens a file in write-only mode
Possibility for TOCTOU attack
ifos.is_writable("file"){// >> time to make a quick attack (e.g. symlink /etc/passwd to >file<) <<
mutf:=os.create('path/to/file')?// <do something with file>
f.close()}
TOCTOU not possible
mutf:=os.create('path/to/file')or{println("file not writable")}// >> do something with file; file is locked <<
f.close()
Proven affected functions
The following functions should be used with care and only when used correctly.