1317 Commits

Author SHA1 Message Date
Yi Fan Yu
dff8fd27ed test/regress.h: Increase default timeval tolerance 50 ms -> 100 ms
The default timeout tolerance is 50 ms,
which causes intermittent failure in many the
related tests in arm64 QEMU.

See: https://bugzilla.yoctoproject.org/show_bug.cgi?id=14163
(The root cause seems to be a heavy load)

Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com>
2021-04-23 10:27:00 -04:00
fanquake
4c29b01c87
build: remove splice implementation fragments
Looks like a `splice` implementation was planned, but has clearly never
eventuated (the TODO comment is from ~12 years ago, in
8b5bd77415fb6634fadf08357676926fecf5f032). For now, it's probably better
to remove the unused code/correct the docs.
2021-03-28 10:57:11 +08:00
lilei
bc25889fb3 Check return value of evbuffer_remove() in bufferevent_read()
The conflict cast convertion between the return value of
bufferevent_read() and evbuffer_remove(), int(-1)->size_t(An undefined
maximum)

Add test case of bufferevent_read() should return 0 in case of
evbuffer_remove() returns -1

Fixes: #1132
2021-02-04 00:20:36 +03:00
Azat Khuzhin
f17eb6f509 test/regress_http: cover reading of chunked payload by server
This is an example with transfer-encoding by client via bufferevent for
the #1131
2021-01-19 01:23:42 +03:00
chux0519
617ba83874 evdns: add max-probe-timeout/probe-backoff-factor settings
I recently found that when the network status changed when calling
bufferevent_socket_connect_hostname (e.g. switching between several
WIFIs), all DNS servers would fail, and the timeout of probe would be
very long if there were many DNS requests. I want libevent to support
manual setting of MAX_PROBE_TIMEOUT and TIMEOUT_BACKOFF_FACTOR

So move hardcoded MAX_PROBE_TIMEOUT and TIMEOUT_BACKOFF_FACTOR into
struct, and allow changing them.
2021-01-12 10:56:13 +03:00
Azat Khuzhin
a490172d69 Introduce new BUFFEREVENT_SSL_BATCH_WRITE flag to avoid Nagle effect in SSL 2020-10-31 23:04:46 +03:00
Azat Khuzhin
e91c436388 http: add EVHTTP_URI_HOST_STRIP_BRACKETS
Refs: #1115
2020-10-27 02:13:21 +03:00
okhowang(王沛文)
53c6867520 test: fix windows error when mbedtls https 2020-09-16 10:04:36 +08:00
okhowang(王沛文)
2403ae578f test: add https with mbedtls 2020-09-14 19:49:08 +08:00
Berbe
c2a9ecffef
Fix: long -> enum evhttp_cmd_type type 2020-08-29 20:05:52 +02:00
Azat Khuzhin
2338f27e69 test/regress_dns: fix -Wmaybe-uninitialized
Was not noticed since it is reported only with optimization enabled, as
stated in gcc(1):

   The effectiveness of some warnings depends on optimizations also
   being enabled. For example -Wsuggest-final-types is more effective with
   link-time optimization and -Wmaybe-uninitialized does not warn at all
   unless optimization is enabled.

And interesting thing is that it is reported only for -O2, not for -O3,
that's why I did not catched it in both cmake env that I had:
- debug (it has -O0)
- release (it has -O3)

While autoconf has -O2.
2020-08-29 01:15:20 +03:00
Azat Khuzhin
eeeed1e1bb test/dns: fix initialize_nameservers when there is ipv6 in /etc/resolv.conf
Fixes: #1060
2020-07-28 01:19:55 +03:00
Azat Khuzhin
53e53b018b test/regress_buffer.c: fix -Wbad-function-cast (in some specific env)
Fixes: #1054
2020-07-23 00:22:45 +03:00
Azat Khuzhin
1bfbbdf2b4 test: rename ssl/* -> openssl/* 2020-07-22 23:10:26 +03:00
okhowang(王沛文)
028385f685 fix build system and add test and cleanup code 2020-07-22 22:53:23 +03:00
Azat Khuzhin
90bcf2d660 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.
2020-07-05 12:16:52 +03:00
Azat Khuzhin
ba19b356bf 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
2020-07-05 11:46:22 +03:00
Azat Khuzhin
7b9ba3b717 test: really disable bufferevent_pair_release_lock under ASAN (and fix gcc) 2020-07-05 11:19:10 +03:00
Azat Khuzhin
e2f938c04f test-closed: fix leak 2020-07-05 11:08:05 +03:00
Azat Khuzhin
0ac3cfc0b7 test: add getaddrinfo(AI_ADDRCONFIG) test (off by default) 2020-06-26 11:32:59 +03:00
Azat Khuzhin
ec94a6bb3f test: fix memory leaks for https (add BEV_OPT_CLOSE_ON_FREE)
- http/https_filter_basic
- http/https_filter_chunk_out
2020-06-25 22:57:53 +03:00
Azat Khuzhin
cdbb2373f4 test: "fix" (with a quirk) leak in ssl/bufferevent_wm (w/o defer callbacks) 2020-06-25 22:57:40 +03:00
Azat Khuzhin
3b13a64789 test: disable bufferevent/bufferevent_pair_release_lock under ASAN (too tricky)
And cannot be suppressed with suppressions due to setup routines.
2020-06-25 22:57:40 +03:00
Azat Khuzhin
6754740f15 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().
2020-06-25 22:57:40 +03:00
Azat Khuzhin
a0c642ac04 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)
2020-06-25 10:15:01 +03:00
Azat Khuzhin
6f152befb4 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
2020-06-25 09:59:35 +03:00
Azat Khuzhin
37dbb35080 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
2020-06-25 09:51:20 +03:00
Azat Khuzhin
2aaa7358a1 test/regress_http: remove second ARRAY_SIZE macros 2020-06-02 10:12:20 +03:00
Azat Khuzhin
8b5a4d61f6 test/regress_testutils: use inet_addr() 2020-06-02 10:01:31 +03:00
Azat Khuzhin
271c5aaa81 test/regress_dns: use tt_int_op() over tt_assert() in assert_request_results() 2020-06-02 10:00:38 +03:00
seleznevae
83c58d4985 evdns: Add support for setting maximum UDP DNS message size.
Added new option `edns-udp-size` for evdns_base which allows
to control maximum allowed size of UDP DNS messages. This
maximum size is passed to the DNS server via edns mechanism.
2020-05-31 19:59:49 +03:00
Azat Khuzhin
7426a568d0 http: Merge branch 'http-max_connections-pr-592'
@jcoffland:

  "When the max connection limit is enabled and the limit is reached, the
   server will respond immediately with 503 Service Unavailable. This can
   be used to prevent servers from running out of file descriptors. This is
   better than request limiting because clients may make more than one
   request over a single connection. Blocking a request does not
   necessarily close the connection and free up a socket."

* http-max_connections-pr-592:
  test: cover evhttp max connections
  Added evhttp max simultaneous connection limiting
2020-05-25 11:25:18 +03:00
Azat Khuzhin
95c1c200c1 test: cover evhttp max connections 2020-05-25 11:24:29 +03:00
Azat Khuzhin
028842aacb Merge branch 'evdns-tcp-pr-1004'
@seleznevae:

  "Added support for DNS requests via TCP. By default, requests are done
   via UDP. In case truncated response is received new attempt is done
   via TCP connection. Added 2 new macros DNS_QUERY_USEVC and
   DNS_QUERY_IGNTC to force all requests to be done via TCP and to disable
   switch to TCP in case of truncated responses.

   Also added possibility for DNS server to listen and receive requests on
   TCP port. Current implementation of TCP support in DNS server seems
   rather preliminary and maybe changes after discussion and code review.

   Fallback to TCP in case of truncated DNS requests is done automatically.
   To imitate the old behaviour macros DNS_QUERY_IGNTC should be used. To
   force all DNS requests to be done via TCP one should use the flag
   DNS_QUERY_USEVC. Names DNS_QUERY_IGNTC, DNS_QUERY_USEVC were chosen to
   imitate similar flags in c-ares and glibc."

Ok, interfaces looks good, merging to avoid stalling it for too long.

* evdns-tcp-pr-1004:
  evdns: fix coding style issues
  evdns: fix trailing whitespaces
  evdns: bufferevent_setcb before bufferevent_free is redundant
  evdns: Implement dns requests via tcp
2020-05-25 03:14:26 +03:00
Azat Khuzhin
e8c8951029 test: http/autofree_connection cleanup 2020-05-25 02:07:44 +03:00
ayuseleznev
0f6ee89a39 evdns: Implement dns requests via tcp 2020-05-21 12:46:20 +03:00
Azat Khuzhin
70f69194eb test: cleanup http/autofree_connection 2020-05-19 01:06:12 +03:00
Azat Khuzhin
1cc94feab8 test: fix http/autofree_connection
Refs: #182
2020-05-19 01:06:02 +03:00
ayuseleznev
8fe35c7614 evdns: Add additional validation for values of dns options 2020-05-18 14:31:49 +03:00
Nick Grifka
83ef3216e4 Add wepoll support to light up the epoll backend on Windows
libevent is lacking a scalable backend on Windows. Let's leverage the wepoll
library until Windows comes up with an epoll/kqueue compete user mode API.

- All regress tests pass for standard wepoll
- These 2 tests fail intermittently for changelist wepoll, so disabling
  changelist wepoll for now
     http/cancel_inactive_server
     http/stream_in
- verify target on Windows runs tests for both wepoll and win32 backends
- wepoll backend preferred over win32 backend
- wepoll version 1.5.6

v2: cleaner backend abstraction. Disallow wepoll on MinGW/Cygwin.
v3: Add wepoll.h to dist
v4: Make sure wepoll source files are excluded from cygwin/mingw builds
v5: Keep win32 as default backend on windows.
v6: Include wepoll in mingw builds. Verified that regress tests pass w/ WEPOLL backend.
v7: Enable wepoll on mingw when building with cmake
v8: Add wepoll testrunner for autotools test target
2020-05-08 23:27:04 +03:00
Nick Grifka
06a1192951 test: Fix test_simpleclose for Windows platform
Replace close with evutil_closesocket
Caught with PR #1006
2020-05-07 21:14:13 -07:00
Azat Khuzhin
972b456bf6 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
2020-05-05 00:25:23 +03:00
Azat Khuzhin
ecb67f6189 test: cover EV_CLOSED with lots of possible scenarious
- trigger *RDHUP via close() <-- has issues
- trigger *RDHUP via shutdown()
- EV_CLOSED
- EV_CLOSED|EV_PERSIST
- EV_CLOSED|EV_ET <!-- has issues
- EV_CLOSED|EV_ET|EV_PERSIST
2020-05-04 23:58:28 +03:00
Azat Khuzhin
c81362b2ec test: rename simpleclose to simpleclose_rw (since it works via write/read) 2020-05-04 23:58:28 +03:00
Nick Grifka
5caffa7a5b bench: Allow backend method selection
-l         list available methods
-m <name>  use method
2020-04-27 10:03:28 -07:00
Azat Khuzhin
4e5a41ca0f 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
2020-03-01 16:42:16 +03:00
Azat Khuzhin
a11edbfa36 test-time: enable debug mode if EVENT_DEBUG_LOGGING_ALL env set 2020-03-01 14:54:36 +03:00
ayuseleznev
4da9f87ccb 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.
2020-02-28 15:06:24 +03:00
yuangongji
5fbe6313ae test-ratelim: add missing free 2020-02-12 22:10:31 +08:00
Azat Khuzhin
f6d7992b05 test: mark common_timeout as retriable
Refs: https://github.com/libevent/libevent/pull/951#issuecomment-576711224
2020-01-24 07:52:06 +03:00