libselinux: Do not clobber errno of the world#445
Open
crrodriguez wants to merge 1 commit intoSELinuxProject:mainfrom
Open
libselinux: Do not clobber errno of the world#445crrodriguez wants to merge 1 commit intoSELinuxProject:mainfrom
crrodriguez wants to merge 1 commit intoSELinuxProject:mainfrom
Conversation
libselinux clobbers errno of all consumers (systemd, sshd you name it)
because its constructors do not properly save and restore errno.
The following program demonstrates it.
int main(void)
{
assert(errno == 0);
/* Just a test, it doesn't matter already clobbered */
if(is_selinux_enabled() < 0) {
perror("not enabled");
return 1;
}
}
if any function sets errno, it is not switched back to the original
value and standards DO NOT require errno to the set to zero before
entering main
Signed-off-by: Cristian Rodríguez <cristian@rodriguez.im>
c3c996c to
1fd585e
Compare
crrodriguez
added a commit
to crrodriguez/systemd
that referenced
this pull request
Sep 28, 2024
standards do not require errno to be reset to zero before entering main, third party libraries like openssl and libcap(1) use ELF constructors that if buggy (1) will clobber errno value to everybody else. Libselinux also clobbers errno in most tests cases (2) ensure that is set to zero before starting. (1) https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=f25a1b7e69f7b33e6afb58b3e38f3450b7d2d9a0 (2) SELinuxProject/selinux#445
Contributor
|
Seems fine, just a nit: the identifier Also the main way of contribution is to send patches via |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
libselinux clobbers errno of all consumers (systemd, sshd you name it) because its constructors do not properly save and restore errno. The following program demonstrates it.
int main(void)
{
assert(errno == 0);
/* Just a test, it doesn't matter already clobbered */
if(is_selinux_enabled() < 0) {
perror("not enabled");
return 1;
}
}
if any function sets errno, it is not switched back to the original value and standards DO NOT require errno to the set to zero before entering main