Description
There are evt_tag_errno
calls all around the code that use the errno
variable directly. In some cases it is not safe, because other evt_tags in msg_(error/warning/etc) can call functions that can overwrite errno. For example in the snippet below, either malloc or strdrup in evt_tag_str can overwrite errno.
As compiler is free to evaluate parameters in any order, it is not enough to move evt_tag_errno to the first parameter.
cap_text = cap_to_text(caps, NULL);
msg_error("Error managing capability set, cap_set_proc returned an error",
evt_tag_str("caps", cap_text),
evt_tag_errno("error", errno));
The resolution would be to store errno on the stack, and pass the local variable to errno.
As a bonus: evt_tag_errno might disallow users to pass errno directly: for example compare if &errno
is passed to it, and assert in that case. G_LIKELY/UNLIKELY can be used inside the if statement for optimization.
As an estimate, 64/76 of evt_tag_errno uses errno directly.
$ ag evt_tag_errno | grep -F "errno)" | wc -l
64
$ ag evt_tag_errno | wc -l
76