Skip to content

Commit

Permalink
shared: ensure errno always zero on entering main
Browse files Browse the repository at this point in the history
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
  • Loading branch information
crrodriguez committed Sep 28, 2024
1 parent 6fd5853 commit a65227d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shared/main-func.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#define _DEFINE_MAIN_FUNCTION(intro, impl, result_to_exit_status, result_to_return_value) \
int main(int argc, char *argv[]) { \
errno = 0; \
int r; \
assert_se(argc > 0 && !isempty(argv[0])); \
save_argc_argv(argc, argv); \
Expand Down
1 change: 1 addition & 0 deletions src/shared/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static inline int run_test_table(void) {

#define DEFINE_TEST_MAIN_FULL(log_level, intro, outro) \
int main(int argc, char *argv[]) { \
errno = 0; \
int (*_intro)(void) = intro; \
int (*_outro)(void) = outro; \
int _r, _q; \
Expand Down

0 comments on commit a65227d

Please sign in to comment.