/** * xmlSecOpenSSLErrorsDefaultCallback: * @file: the error location file name (__FILE__ macro). * @line: the error location line number (__LINE__ macro). * @func: the error location function name (__FUNCTION__ macro). * @errorObject: the error specific error object * @errorSubject: the error specific error subject. * @reason: the error code. * @msg: the additional error message. * * The default OpenSSL errors reporting callback function. */ void xmlSecOpenSSLErrorsDefaultCallback(const char* file, int line, const char* func, const char* errorObject, const char* errorSubject, int reason, const char* msg) { ERR_put_error(XMLSEC_OPENSSL_ERRORS_LIB, XMLSEC_OPENSSL_ERRORS_FUNCTION, reason, file, line); xmlSecErrorsDefaultCallback(file, line, func, errorObject, errorSubject, reason, msg); }
END_TEST /** * In an old version of the code that used strncat, this caused a SIGSEGV. */ START_TEST(test_openssl_error_longfilename) { ERR_clear_error(); #define fn10 "1234567890" #define fn50 fn10 fn10 fn10 fn10 fn10 #define fn250 fn50 fn50 fn50 fn50 fn50 #define fn1000 fn250 fn250 fn250 fn250 ERR_put_error(ERR_LIB_SYS, SYS_F_FOPEN, ERR_R_SYS_LIB, fn1000, 1); ERR_put_error(ERR_LIB_SYS, SYS_F_FOPEN, ERR_R_SYS_LIB, fn1000, 1); PUSH_ERROR_OPENSSL(); const errinfo_t *last_error = get_last_error(); ck_assert_ptr_ne(NULL, last_error); ck_assert_int_eq(ERR_OPENSSL, last_error->errcode); ck_assert_uint_eq(sizeof(last_error->auxmsg) - 1, strlen(last_error->auxmsg)); }
END_TEST START_TEST(test_openssl_error_100) { ERR_clear_error(); for (int i = 0; i < 100; i++) { ERR_put_error(ERR_LIB_SYS, SYS_F_FOPEN, ERR_R_SYS_LIB, "filename", 100 + i); } PUSH_ERROR_OPENSSL(); const errinfo_t *last_error = get_last_error(); ck_assert_ptr_ne(NULL, last_error); ck_assert_int_eq(ERR_OPENSSL, last_error->errcode); ck_assert_uint_eq(sizeof(last_error->auxmsg) - 1, strlen(last_error->auxmsg)); }
END_TEST START_TEST(test_openssl_error_5) { ERR_clear_error(); for (int i = 0; i < 5; i++) { ERR_put_error(ERR_LIB_SYS, SYS_F_FOPEN, ERR_R_SYS_LIB, "filename", 100); } PUSH_ERROR_OPENSSL(); const errinfo_t *last_error = get_last_error(); ck_assert_ptr_ne(NULL, last_error); ck_assert_int_eq(ERR_OPENSSL, last_error->errcode); ck_assert_str_eq(ERRMSG SEP ERRMSG SEP ERRMSG SEP ERRMSG SEP ERRMSG, last_error->auxmsg); }