Skip to content

Commit a65227d

Browse files
committed
shared: ensure errno always zero on entering main
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
1 parent 6fd5853 commit a65227d

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/shared/main-func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#define _DEFINE_MAIN_FUNCTION(intro, impl, result_to_exit_status, result_to_return_value) \
2222
int main(int argc, char *argv[]) { \
23+
errno = 0; \
2324
int r; \
2425
assert_se(argc > 0 && !isempty(argv[0])); \
2526
save_argc_argv(argc, argv); \

src/shared/tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static inline int run_test_table(void) {
184184

185185
#define DEFINE_TEST_MAIN_FULL(log_level, intro, outro) \
186186
int main(int argc, char *argv[]) { \
187+
errno = 0; \
187188
int (*_intro)(void) = intro; \
188189
int (*_outro)(void) = outro; \
189190
int _r, _q; \

0 commit comments

Comments
 (0)