diff options
author | David Goulet <dgoulet@torproject.org> | 2019-02-13 11:02:02 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-02-13 11:02:02 -0500 |
commit | d5de1a0a5514c51d39f8acdb0c906a186854e681 (patch) | |
tree | 2dbda77a9f42d984f7dfc27fc0d837380766e9e0 /src | |
parent | c320c52e89d0d950f0316d2c2f070f7adca66c80 (diff) | |
parent | bbe417ae8f2eff9b1ec50411dc50d4f0281c1778 (diff) | |
download | tor-d5de1a0a5514c51d39f8acdb0c906a186854e681.tar.gz tor-d5de1a0a5514c51d39f8acdb0c906a186854e681.zip |
Merge branch 'tor-github/pr/651'
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/encoding/time_fmt.c | 4 | ||||
-rw-r--r-- | src/test/test_address.c | 2 | ||||
-rw-r--r-- | src/test/test_pt.c | 6 | ||||
-rw-r--r-- | src/test/test_util.c | 24 | ||||
-rw-r--r-- | src/test/testing_common.c | 18 |
5 files changed, 53 insertions, 1 deletions
diff --git a/src/lib/encoding/time_fmt.c b/src/lib/encoding/time_fmt.c index 5b2440d1ab..40543d41e0 100644 --- a/src/lib/encoding/time_fmt.c +++ b/src/lib/encoding/time_fmt.c @@ -39,6 +39,8 @@ * * Convert *<b>timep</b> to a struct tm in local time, and store the value in * *<b>result</b>. Return the result on success, or NULL on failure. + * + * Treat malformatted inputs localtime outputs as a BUG. */ struct tm * tor_localtime_r(const time_t *timep, struct tm *result) @@ -56,6 +58,8 @@ tor_localtime_r(const time_t *timep, struct tm *result) * * Convert *<b>timep</b> to a struct tm in UTC, and store the value in * *<b>result</b>. Return the result on success, or NULL on failure. + * + * Treat malformatted inputs or gmtime outputs as a BUG. */ struct tm * tor_gmtime_r(const time_t *timep, struct tm *result) diff --git a/src/test/test_address.c b/src/test/test_address.c index 6cfe461b65..d9304a0cfa 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -1015,7 +1015,7 @@ test_address_get_if_addrs6(void *arg) (void)arg; - rv = get_interface_address6(LOG_ERR, AF_INET6, &tor_addr); + rv = get_interface_address6(LOG_WARN, AF_INET6, &tor_addr); /* Work even on systems without IPv6 interfaces */ if (rv == 0) { diff --git a/src/test/test_pt.c b/src/test/test_pt.c index d1ea609c3e..d2996f4cc3 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -23,6 +23,8 @@ #include "app/config/or_state_st.h" +#include "test/log_test_helpers.h" + static void reset_mp(managed_proxy_t *mp) { @@ -414,7 +416,10 @@ test_pt_configure_proxy(void *arg) "650 TRANSPORT_LAUNCHED server mock5 127.0.0.1 5555\r\n"); /* Get the log message out. */ + setup_full_capture_of_logs(LOG_ERR); process_notify_event_stdout(mp->process); + expect_single_log_msg_containing("Oh noes, something bad happened"); + teardown_capture_of_logs(); tt_int_op(controlevent_n, OP_EQ, 10); tt_int_op(controlevent_event, OP_EQ, EVENT_PT_LOG); @@ -475,6 +480,7 @@ test_pt_configure_proxy(void *arg) } done: + teardown_capture_of_logs(); or_state_free(dummy_state); UNMOCK(process_read_stdout); UNMOCK(get_or_state); diff --git a/src/test/test_util.c b/src/test/test_util.c index 4e95303f2e..77a4474522 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -712,6 +712,12 @@ test_util_time(void *arg) expect_single_log_msg_containing(msg); \ teardown_capture_of_logs(); \ } while (0) +#define CHECK_POSSIBLE_EINVAL() do { \ + if (mock_saved_log_n_entries()) { \ + expect_single_log_msg_containing("Invalid argument"); \ + } \ + teardown_capture_of_logs(); \ + } while (0) #define CHECK_TIMEGM_ARG_OUT_OF_RANGE(msg) \ CHECK_TIMEGM_WARNING("Out-of-range argument to tor_timegm") @@ -907,12 +913,16 @@ test_util_time(void *arg) if (sizeof(time_t) == 4 || sizeof(time_t) == 8) { t_res = -1*(1 << 30); + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1935-1900)); t_res = INT32_MIN; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1901-1900)); } @@ -922,7 +932,9 @@ test_util_time(void *arg) /* one of the smallest tm_year values my 64 bit system supports: * b_time.tm_year == (-292275055LL-1900LL) without clamping */ t_res = -9223372036854775LL; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1-1900)); @@ -948,7 +960,9 @@ test_util_time(void *arg) { /* As above, but with localtime. */ t_res = -9223372036854775LL; + CAPTURE(); tor_localtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (1970-1900) || b_time.tm_year == (1-1900)); @@ -1005,7 +1019,9 @@ test_util_time(void *arg) /* one of the largest tm_year values my 64 bit system supports: * b_time.tm_year == (292278994L-1900L) without clamping */ t_res = 9223372036854775LL; + CAPTURE(); tor_gmtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (2037-1900) || b_time.tm_year == (9999-1900)); @@ -1026,7 +1042,9 @@ test_util_time(void *arg) { /* As above but with localtime. */ t_res = 9223372036854775LL; + CAPTURE(); tor_localtime_r(&t_res, &b_time); + CHECK_POSSIBLE_EINVAL(); tt_assert(b_time.tm_year == (2037-1900) || b_time.tm_year == (9999-1900)); @@ -1069,7 +1087,10 @@ test_util_time(void *arg) /* This value is out of range with 32 bit time_t, but in range for 64 bit * time_t */ + CAPTURE(); format_rfc1123_time(timestr, (time_t)2150000000UL); + CHECK_POSSIBLE_EINVAL(); + #if SIZEOF_TIME_T == 4 #if 0 /* Wrapping around will have made it this. */ @@ -1238,7 +1259,9 @@ test_util_time(void *arg) /* This value is out of range with 32 bit time_t, but in range for 64 bit * time_t */ tv.tv_sec = (time_t)2150000000UL; + CAPTURE(); format_iso_time(timestr, (time_t)tv.tv_sec); + CHECK_POSSIBLE_EINVAL(); #if SIZEOF_TIME_T == 4 /* format_iso_time should indicate failure on overflow, but it doesn't yet. * Hopefully #18480 will improve the failure semantics in this case. @@ -1253,6 +1276,7 @@ test_util_time(void *arg) #undef CAPTURE #undef CHECK_TIMEGM_ARG_OUT_OF_RANGE +#undef CHECK_POSSIBLE_EINVAL done: teardown_capture_of_logs(); diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 4e603b529a..8fc8ef7830 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -241,6 +241,15 @@ tinytest_postfork(void) init_pregenerated_keys(); } +static void +log_callback_failure(int severity, uint32_t domain, const char *msg) +{ + (void)msg; + if (severity == LOG_ERR || (domain & LD_BUG)) { + tinytest_set_test_failed_(); + } +} + /** Main entry point for unit test code: parse the command line, and run * some unit tests. */ int @@ -280,6 +289,7 @@ main(int c, const char **v) c = i_out; { + /* setup logs to stdout */ log_severity_list_t s; memset(&s, 0, sizeof(s)); set_log_severity_config(loglevel, LOG_ERR, &s); @@ -287,6 +297,14 @@ main(int c, const char **v) s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; add_stream_log(&s, "", fileno(stdout)); } + { + /* Setup logs that cause failure. */ + log_severity_list_t s; + memset(&s, 0, sizeof(s)); + set_log_severity_config(LOG_ERR, LOG_ERR, &s); + s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; + add_callback_log(&s, log_callback_failure); + } flush_log_messages_from_startup(); init_protocol_warning_severity_level(); |