1265 Commits

Author SHA1 Message Date
Azat Khuzhin
a03f0f8a54 test: fix leak in dns/getaddrinfo_cancel_stress
Some requests may get response (evutil_addrinfo) from gaic_server_cb,
in case of cancel_event (10000ms) will not be fast enough.

(cherry picked from commit 90bcf2d660b9b43cb8e747421d4938f08f935bd7)
2020-07-05 12:17:15 +03:00
Azat Khuzhin
777cc2b6b5 test: fix UB in evbuffer/empty_reference_prepend_buffer
UBSAN reports:
  test/regress_buffer.c:2360:2: runtime error: null pointer passed as argument 1, which is declared to never be null
  /usr/include/string.h:140:33: note: nonnull attribute specified here

(cherry picked from commit ba19b356bf8a9be2a5bddfa264dee61ffc9573a7)
2020-07-05 11:48:31 +03:00
Azat Khuzhin
82ae28e1d7 test: really disable bufferevent_pair_release_lock under ASAN (and fix gcc)
(cherry picked from commit 7b9ba3b717af109abdf3fb5fc99c288dc8024ef5)
2020-07-05 11:36:30 +03:00
Azat Khuzhin
ff67e8c268 test-closed: fix leak
(cherry picked from commit e2f938c04f9a72f6fd6ca9b7a8219ca9cb409d69)
2020-07-05 11:36:30 +03:00
Azat Khuzhin
4d3ff29cac test: add getaddrinfo(AI_ADDRCONFIG) test (off by default)
(cherry picked from commit 0ac3cfc0b70edc2cfb429712d6aaf1b3a63d2d1a)
2020-06-28 21:38:40 +03:00
Azat Khuzhin
ccd6724300 test: fix memory leaks for https (add BEV_OPT_CLOSE_ON_FREE)
- http/https_filter_basic
- http/https_filter_chunk_out

(cherry picked from commit ec94a6bb3f9d950101d07b2a2e092b675d5aa3f0)
2020-06-28 21:38:36 +03:00
Azat Khuzhin
3c2c856de4 test: "fix" (with a quirk) leak in ssl/bufferevent_wm (w/o defer callbacks)
(cherry picked from commit cdbb2373f4d13f7a5eb69daaf0a172779ccc0040)
2020-06-28 21:38:05 +03:00
Azat Khuzhin
66341e84bc test: disable bufferevent/bufferevent_pair_release_lock under ASAN (too tricky)
And cannot be suppressed with suppressions due to setup routines.

(cherry picked from commit 3b13a64789b3942608f04c31455668bebe224a40)
2020-06-28 21:38:05 +03:00
Azat Khuzhin
19a68bd194 test: detect test failures if atexit handler calls _exit(!0) (sanitizers)
tinytest uses another way of detecting test failures, it uses pipe
between child and parent, and if the test function in child returns OK
it writes OK flag into pipe, and reads it in parent.

However sanitizers uses atexit handlers to detect leaks, and this will
not detect failures in case of exit() will be called from the atexit
handlers, fix this by checking status after waitpid().

(cherry picked from commit 6754740f15e8200a12605a2e707fc6d3e6754d6a)
2020-06-28 21:38:05 +03:00
Azat Khuzhin
5b063049cf buffer: do not pass NULL to memcpy() from evbuffer_pullup()
UBSAN reports:

  evbuffer/remove_buffer_with_empty3: ../buffer.c:1443:3: runtime error: null pointer passed as argument 2, which is declared to never be null
      #0 0x7ffff6cd0410 in evbuffer_pullup ../buffer.c:1443
      #1 0x5555556d68b9 in test_evbuffer_remove_buffer_with_empty3 ../test/regress_buffer.c:408
      #2 0x5555557b95ee in testcase_run_bare_ ../test/tinytest.c:173
      #3 0x5555557ba048 in testcase_run_one ../test/tinytest.c:333
      #4 0x5555557bc0f8 in tinytest_main ../test/tinytest.c:527
      #5 0x555555787702 in main ../test/regress_main.c:528
      #6 0x7ffff606c001 in __libc_start_main (/usr/lib/libc.so.6+0x27001)
      #7 0x55555569436d in _start (/src/le/libevent/.cmake-debug/bin/regress+0x14036d)

(cherry picked from commit a0c642ac04487d8cda809bd6e233b0fbd043806d)
2020-06-28 21:37:40 +03:00
Azat Khuzhin
a91abd0e8e test: do not pass NULL to memcmp() in evbuffer_datacmp() helper
Fixes:
  runtime error: null pointer passed as argument 2, which is declared to never be null
(cherry picked from commit 6f152befb4523fd2e57c1a937e590f8ff87b7f15)
2020-06-28 21:37:40 +03:00
Azat Khuzhin
6b8d02a755 http: fix undefined-shift in EVUTIL_IS*_ helpers
evutil.c:2559:1: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
    #0 0x4f2be0 in EVUTIL_ISXDIGIT_ libevent/evutil.c:2559:1
    #1 0x4bd689 in regname_ok libevent/http.c:4838:7
    #2 0x4bc16b in parse_authority libevent/http.c:4958:9
    #3 0x4bb8b5 in evhttp_uri_parse_with_flags libevent/http.c:5103:7
    #4 0x4bb762 in evhttp_uri_parse libevent/http.c:5050:9
    #5 0x4b8f41 in evhttp_parse_query_impl libevent/http.c:3505:9
    #6 0x4b8ed7 in evhttp_parse_query libevent/http.c:3569:9

Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23291
Report: https://oss-fuzz.com/testcase-detail/5670743106125824
(cherry picked from commit 37dbb3508099d49748453166c1ee9ef1603fcf3a)
2020-06-28 21:37:40 +03:00
Azat Khuzhin
fb5fa12ac0 test/regress_testutils: use inet_addr()
(cherry picked from commit 8b5a4d61f6eb7180c0800f38549c20776c6d1cd9)
2020-06-28 21:36:02 +03:00
Azat Khuzhin
65a002a8e5 test: http/autofree_connection cleanup
(cherry picked from commit e8c8951029a0a084dd73b27e6dc3b637a7c914db)
2020-06-28 21:35:11 +03:00
Azat Khuzhin
8dc6468e7e test: cleanup http/autofree_connection
(cherry picked from commit 70f69194eb3b19b5e41b52b17a820e1e91512560)
2020-06-28 21:34:56 +03:00
Azat Khuzhin
ab13087526 test: fix http/autofree_connection
Refs: #182
(cherry picked from commit 1cc94feab81e7387041edc32be9843f66847072d)
2020-06-28 21:33:12 +03:00
ayuseleznev
c297245377 evdns: Add additional validation for values of dns options
(cherry picked from commit 8fe35c7614802fa13d144cceea9b079d5a131891)
2020-06-28 21:33:12 +03:00
Nick Grifka
141e37c804 test: Fix test_simpleclose for Windows platform
Replace close with evutil_closesocket
Caught with PR #1006

(cherry picked from commit 06a11929511bebaaf40c52aaf91de397b1782ba2)
2020-06-28 21:33:12 +03:00
Azat Khuzhin
1df324d4c4 Fix EV_CLOSED detection/reporting (epoll only)
- EV_CLOSED is EPOLLRDHUP in epoll
- EPOLLRDHUP reported w/o EPOLLHUP if the socket closed with shutdown(SHUT_WR)
- EPOLLRDHUP reported w/  EPOLLHUP if the socket closed with close()
  so in this case epoll backend will detect this event as error
  (EV_READ|EV_WRITE), since the epoll_ctl() will return EPOLLRDHUP with
  EPOLLHUP set, but this is not correct, let's fix this.

Fixes: #984
(cherry picked from commit 972b456bf60e9a2f550ec45a14921c06e252c793)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
db2efdf55e Merge branch 'EV_CLOSED-and-EV_ET-fixes'
* EV_CLOSED-and-EV_ET-fixes:
  Avoid triggering wrong events with EV_ET set
  epoll: handle EV_ET for EV_CLOSED too
  test: cover EV_CLOSED with lots of possible scenarious
  test: rename simpleclose to simpleclose_rw (since it works via write/read)

(cherry picked from commit c10cde4c617979e951352775a9685a47bf9c6acd)
2020-06-28 21:33:11 +03:00
Nick Grifka
1fce771dc8 bench: Allow backend method selection
-l         list available methods
-m <name>  use method

(cherry picked from commit 5caffa7a5b3ce67e074e2ee99fc553c1cac0712c)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
e41a1969b0 test-time: do not use deprecated API
- event_init() -> event_base_new()
- event_set() -> event_new()
- check return value of event_base_dispatch()
- use EXIT_SUCCESS/EXIT_FAILURE

(cherry picked from commit 4e5a41ca0f668da1a18832e5cb02b4afeae074ff)
2020-06-28 21:24:21 +03:00
Azat Khuzhin
29e2c7f2b7 test-time: enable debug mode if EVENT_DEBUG_LOGGING_ALL env set
(cherry picked from commit a11edbfa369f7a99886359b3f4baa69686dc275f)
2020-06-28 21:24:21 +03:00
ayuseleznev
6f8e0e97e5 evdns: fix a crash when evdns_base with waiting requests is freed
Fix undefined behaviour and application crash that might take
place in some rare cases after calling evdns_base_free when
there are requests in the waiting queue.

Current cleanup procedure in evdns_base_free_and_unlock
function includes 2 steps:
1. Finish all inflight requests.
2. Finish all waiting requests.
During the first step we iterate over each list in req_heads
structure and finish all requests in these lists. With current
logic finishing an inflight request (function request_finished)
removes it from the inflight requests container and forces
a wating connection to be sent (by calling
evdns_requests_pump_waiting_queue). When these new requests are
sent it is possible that they will be inserted to the list in
req_heads that we've already cleaned.
So in some cases container of the inflight requests is not empty
after this procedure and some requests are not finished and
deleted. When timeouts for these requests expire
evdns_request_timeout_callback is called but corresponding
evdns_base has been already deleted which causes undefined
behaviour and possible applicaton crash.

It is interesting to note that in old versions of libevent such
situation was not possible. This bug was introduced by the commit
14f84bbdc77d90b1d936076661443cdbf516c593. Before this commit
nameservers were deleted before finishing the requests. Therefore
it was not possible that requests from the waiting queue be sent
while we finish the inflight requests.

(cherry picked from commit 4da9f87ccbe71edb3b3aaf74b8b64d7e9c41dcaf)
2020-06-28 21:24:21 +03:00
yuangongji
9e993c3cdb test-ratelim: add missing free
(cherry picked from commit 5fbe6313ae7e81cde3e056b29171a6346c54aa0b)
2020-06-28 21:24:21 +03:00
Azat Khuzhin
0ef87f5f0e test: move thread into realtime class even on EVENT__DISABLE_THREAD_SUPPORT
(cherry picked from commit ca2b72c546d80dfb4fa255b20ef4a829ed102a70)
2020-06-28 21:24:17 +03:00
Azat Khuzhin
5a400c1f28 test: fix compilation without thread support (EVENT__DISABLE_THREAD_SUPPORT=ON)
(cherry picked from commit d0adbc05654eca27384b6496cfd8a22ed4dfb4fb)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
1121ebed84 test: fix bufferevent/bufferevent_connect_fail_eventcb* under osx/freebsd
For OSX the socket should be closed, otherwise the "connection refused"
will not be triggered.

And freebsd can return error from the connect().

(cherry picked from commit 30fe125041ab38045487bd3af60d2f564dffc81c)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
d5d18a5644 test: fix dst thread in move_pthread_to_realtime_scheduling_class (osx)
Fixes the following tests on osx:
- del_wait
- no_events

Refs: #940
(cherry picked from commit 10504fcab927e8b226ef2e988b1b3f175c3e9f71)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
265cbe1077 test: fix compilation under win32 (rearrange thread_setup() code)
(cherry picked from commit 34d51e1bc9c650c4d012fe3024f7777c819ba969)
2020-06-28 21:22:37 +03:00
Azat Khuzhin
8991346df9 test: use THREAD_* wrappers over pthread* in del_notify
(cherry picked from commit 391003e9b78acff0ee5096c592fc4b601a02648d)
2020-06-28 21:22:03 +03:00
Azat Khuzhin
e85afbe3d5 Merge branch 'osx-clock'
Moves the thread into real-time scheduling class, as recommended in [1], it
fixes the separate test provided by @ygj6 [2] everywhere (github actions,
travis-ci, appveyor) under osx.

  [1]: https://developer.apple.com/library/archive/technotes/tn2169/_index.html
  [2]: dde1a6e4d0

Although even after this changes the following time-related tests failed
on travis-ci:
- no_events
- del_wait

But anyway I guess #940 can be closed, since this fixes the issue in common.

* osx-clock:
  test: Use THREAD_* wrappers in del_notify/del_wait
  test: move threads created with THREAD_START() to realtime scheduling class too
  test: put thread into real time scheduling class on osx for better latencies

Closes: #940
(cherry picked from commit a6f81aa45455c8afb69980f7026a0e706f4f9387)
2020-06-28 21:21:56 +03:00
Azat Khuzhin
921bdcdd81 Fix compilation without OPENSSL_API_COMPAT
Use the following for openssl 1.1+:
- X509_getm_notBefore over X509_get_notBefore
- X509_getm_notAfter  over X509_get_notAfter
- use OPENSSL_VERSION_NUMBER over SSLeay()
- add missing headers

Refs: openssl/openssl@0b7347effe
(cherry picked from commit 08981f8d752ad23e21887b42944783e843b2e281)
2020-06-28 21:20:46 +03:00
Azat Khuzhin
8ad26d0b11 test-ratelim: calculate timers bias (for slow CPUs) to avoid false-positive
This can be/should be done for regression tests too.

Refs: https://ci.appveyor.com/project/libevent/libevent/builds/28916689/job/kg621aa194a0qbym
Refs: https://github.com/libevent/libevent/pull/917#issuecomment-553811834
v2: EVENT_BASE_FLAG_PRECISE_TIMER
(cherry picked from commit 8a34869984c470fb243fc9587c469b316add2f7e)
2020-06-28 21:19:54 +03:00
Philip Homburg
f602211fa1 Parse IPv6 scope IDs.
(cherry picked from commit 9fecb59a94ef246088d7f3e0365c2fe80d0df2f4)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
ca92a7559e Relax bufferevent_connect_hostname_emfile
Do not do any assumptions on the error for the EMFILE from
getaddrinfo(), expect just any error.

Fixes: #924
(cherry picked from commit 4436287d1247fb2e9c80560debf852a94657e485)
2020-06-28 21:19:42 +03:00
yuangongji
794e8f75b5 tinytest: support timeout on Windows
(cherry picked from commit 8d5c5650d281019832fa7b5133b85c7ad29f664e)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
a4f0387c22 Merge branch 'upstream/pr/899' (evbuffer_freeze testcase enhancements)
* upstream/pr/899:
  improve the description of parameter to evbuffer_read()
  regress_buffer: improve testcase for evbuffer_freeze()

(cherry picked from commit a977d6963611c729b75108d31bf74718b7b3e06d)
2020-06-28 21:17:33 +03:00
yuangongji
9e468c7742 eliminate some C4267 warnings in Windows
(cherry picked from commit 6f970267b6ba68c9dd9090d789c928529745dc68)
2020-06-28 21:16:53 +03:00
Jan Kasiak
8ccd8f561b Fix memory corruption in EV_CLOSURE_EVENT_FINALIZE with debug enabled
Call event_debug_note_teardown_ before evcb_evfinalize to avoid possible
UAF (if finalizer free's event).

(cherry picked from commit 445027a5dcfe0acce431b7d4065d2ac1f6b270d7)
2020-06-28 21:14:32 +03:00
Jan Kasiak
23af76de0a test: prevent duplicate event_enable_debug_mode() for TT_ENABLE_DEBUG_MODE
(cherry picked from commit 70daa93a514075eb0102eec4c6e5002b114264a9)
2020-06-28 21:14:32 +03:00
Azat Khuzhin
0126814f2f test: introduce TT_ENABLE_DEBUG_MODE flag
(cherry picked from commit 6186d3126f124494dd90b14f62c17b47f7a7f484)
2020-06-28 21:14:32 +03:00
dota17
ec52e6af2f Fix typos in comments (sample/test/event-internal.h)
(cherry picked from commit 9c151f3c3413c5ee6bad498aca84be481196bbc7)
2020-06-28 21:14:32 +03:00
Azat Khuzhin
598f247d98
buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM
[ @azat:

  - add return heredoc for evbuffer_setcb()
  - add unit test with event_set_mem_functions()
  - look through the report from abi-compliance-checker/abi-dumper
]

Closes: #855
(cherry picked from commit bdcade47224f154052c927aed3c363a18b37112e)
2019-08-02 00:08:41 +03:00
Azat Khuzhin
546a366ca3
evdns: add new options -- so-rcvbuf/so-sndbuf
This will allow to customize SO_RCVBUF/SO_SNDBUF for nameservers in this
evdns_base, you may want to adjust them if the kernel starts dropping
udp packages.

(cherry picked from commit 538141eb7e590bc94c043b43b5e5483b13bc9c5e)
2019-08-02 00:05:49 +03:00
Azat Khuzhin
2fea04b30e
Merge branch 'evbuffer-fixes-806-v2'
* evbuffer-fixes-806-v2:
  evbuffer: fix last_with_datap after prepend with empty chain
  test: regression for evbuffer_expand_fast_() with invalid last_with_datap
  test: cover adjusting of last_with_datap in evbuffer_prepend()

Fixes: #806
(cherry picked from commit 3b1864b625ec37c3051512845982f347f4cc5621)
2019-05-25 21:25:33 +03:00
Azat Khuzhin
87fa93a8e6
Merge remote-tracking branch 'official/pr/804'
* official/pr/804:
  Added test for evmap slot validations.
  Prevent endless loop in evmap_make_space.
  Enforce limit of NSIG signals.

(cherry picked from commit c6becb26cad8dab2668fe3d913e5ee757bade2fd)
2019-05-25 21:25:12 +03:00
Azat Khuzhin
89932001f2
Disable logging for tests that assume printing warnings
To avoid possible confusion

But there is still one test that has some messages on windows:
  main/methods

Because this test needs >1 of avaiable methods, otherwise it will warn.

(cherry picked from commit 47d348a63130c91f2a6aadef291ff5687275df72)
2019-05-25 21:25:12 +03:00
Azat Khuzhin
58e81106ad
evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT
- DNS_OPTION_NAMESERVERS_NO_DEFAULT
  Do not "default" nameserver (i.e. "127.0.0.1:53") if there is no nameservers
  in resolv.conf, (iff DNS_OPTION_NAMESERVERS is set)

- EVDNS_BASE_NAMESERVERS_NO_DEFAULT
  If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default
  nameserver if there are no nameservers in resolv.conf (just set
  DNS_OPTION_NAMESERVERS_NO_DEFAULT internally)

Fixes: #569
(cherry picked from commit e5b8f4c1925867d8e4cd7dc0390e5141d7ef1106)
2019-05-25 21:25:11 +03:00
Azat Khuzhin
22380996db
Link test/regress with event_core/event_extra over event
Due to regress linked with event and event_core (both of them includes
evthread.c) there will be two different evthread_id_fn_ variables under
mingw64:
  evthread_id_fn_: &0x5294f20a8
  evthread_id_fn_: &0x4ba0030a8

And because of this evthread_use_pthreads() can/will set one copy of
variables while evthread*() functions will access another, which will
break a lot of things (for example main/del_notify test).

Fixes: #792
(cherry picked from commit 2ae875ed1216a8896d8af0414cb4efbcb907bae5)
2019-05-25 21:25:11 +03:00