4168 Commits

Author SHA1 Message Date
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
97e28f09ed Check error code of evhttp_add_header_internal() in evhttp_parse_query_impl()
(cherry picked from commit 4528d8e98781be794cbce13394f8442dd466684b)
2020-06-28 21:37:35 +03:00
Paul Osborne
a62ec76561 cmake: avoid problems from use of CMAKE_USE_PTHREADS_INIT
In some CMake integrations, portions of the toolchain may end up
defining CMAKE_USE_PTHREADS_INIT even when EVENT__DISABLE_THREAD_SUPPORT
is set for libevent.  Modify the build to not rely on this side effect
of find_package(Threads, ...) [which could be done elsewhere] but instead
to use EVENT__HAVE_PTHREADS which is defined only on the desired codepath.

Without this change, affected builds fail as a result of event_pthreads source
files being built but with build defines which cause the build to fail.

Signed-off-by: Paul Osborne <paul.osborne@smartthings.com>
(cherry picked from commit 26d5ff457c9e6cf9b84ec9d8fb83d87caf083d96)
2020-06-28 21:36:58 +03:00
Azat Khuzhin
fb5fa12ac0 test/regress_testutils: use inet_addr()
(cherry picked from commit 8b5a4d61f6eb7180c0800f38549c20776c6d1cd9)
2020-06-28 21:36:02 +03:00
yuangongji
9a94cd9b49 remove FindGit.cmake, improve git describe command
(cherry picked from commit a9aa2b3607c8adf9846aa6a01e070130f4d6dcb9)
2020-06-28 21:35:11 +03:00
Azat Khuzhin
da11fcc881 checkpatch.sh: fix clang-format-diff usage
- strip 1 path component
- it does not accept file name anymore, only stdin

Refs: #1029
(cherry picked from commit 89d313b14dffed7271f41f4e2d68ccfe6b6475ed)
2020-06-28 21:35:11 +03:00
Azat Khuzhin
9c2b49c772 checkpatch.sh: fix usage
Refs: #1029
(cherry picked from commit 8209a623addf6688243eeb6ebb9ece6a20206437)
2020-06-28 21:35:11 +03:00
Wataru Ashihara
b0e9577f36 Fix clang-format-diff usage
"--style" is invalid:

$ ./checkpatch.sh -r HEAD
usage: clang-format-diff [-h] [-i] [-p NUM] [-regex PATTERN] [-iregex PATTERN]
                         [-sort-includes] [-v] [-style STYLE] [-binary BINARY]
clang-format-diff: error: unrecognized arguments: --style={ Language:... }

(cherry picked from commit 866fbb54570c74f215208b237ddce48fb79d2cd6)
2020-06-28 21:35:11 +03:00
mohuang
0970e25c23 variable redefinition in win32_dispatch
(cherry picked from commit f10aaea37433b60ed3e0b7adcc7b1764c8b0b518)
2020-06-28 21:35:11 +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
1be25938b0 http: fix EVHTTP_CON_AUTOFREE in case of timeout (and some else)
Refs: #182
(cherry picked from commit eee26deed38fc7a6b6780b54628b007a2810efcd)
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
2af1f6cc2d abi-check: abi-monitor 1.10 does not support -make -j8 (1.12 supports though)
An error for 1.10 on ci:
  https://github.com/azat/libevent/runs/647860649?check_suite_focus=true#step:4:219

(cherry picked from commit 448a478a98ae7797c1d1a5f1463c02f1b09982f2)
2020-06-28 21:33:11 +03:00
yuangongji
709210d457 Add API/ABI checker (using LVC)
v2 (by azat):
- drop package installations
- use local .abi-check over $HOME/abi-check for build dir
- drop regex check, simply use default values (too complex otherwise)
- use sub-shell to avoid cd back
- add missing quotes
- make the style uniq across the whole file (no tabs for indent, copy-paste?)
- drop `set -x`, use `bash -x abi-check.sh` over
- drop EVENT_ABI_CHECK
- use /usr/bin/env bash as shebang
- use `find | xargs` over `cp $(grep -v)`
- adjust markdown syntax in abi-check/README.md
- adjust link to the publicly available documentation

v3 (by azat):
- docker image
- git check-ignore
- make -j8
- allow to change defaults

Refs: #887
(cherry picked from commit 735c891e71dc7de737dc09cdef26683eea394e66)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
2016f017b3 Update list of cmake files for autotools dist archive
Fixes: #976
(cherry picked from commit f3bc532735c4ac91c5be31ed5f0ca58241a0e983)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
9ea60ab2c1 Pass --quiet to the event_rcpgen.py (autotools already does this)
(cherry picked from commit 7a465268b29c57958e55dceda77ad8322e247454)
2020-06-28 21:33:11 +03:00
Aleksandr-Melnikov
891adda9f1 There is typo in GetAdaptersAddresses windows library. It should be iphlpapi.dll
(cherry picked from commit 61fc2bf2e9719eb7ca9c56b6e186df2f79f05de7)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
2530e7c630 Support EV_CLOSED on linux for poll(2)
Refs: #984
(cherry picked from commit 4c13afaeec2d35df2580dfbc49391d0524101248)
2020-06-28 21:33:11 +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
Nicolas J. Bouliane
4dd3acddf8 bufferevent: allow setting priority on socket and openssl type
(cherry picked from commit bdc5200acdf0a004ddc805b87bf09439fe2ebe7f)
2020-06-28 21:33:11 +03:00
yuangongji
a6974d1132 cmake: set a default value for LIBEVENT_STATIC_LINK
(cherry picked from commit 86eafc03433cb5719e5b75ff99ffab8633433a17)
2020-06-28 21:33:11 +03:00
Nick Grifka
a821914368 evutil_time: improve evutil_gettimeofday on Windows
If present, use GetSystemTimePreciseAsFileTime instead of
GetSystemTimeAsFileTime. Available since Windows 8.

(cherry picked from commit f0b3160f8ce7fbd411493dcd023f562f4f9d17ee)
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
9ed49f2d64 cmake: missing test-closed binary
(cherry picked from commit 57862901095a97306e74b2944d5808051f813ed5)
2020-06-28 21:33:11 +03:00
Azat Khuzhin
f0ded5f313 Merge branch 'event_rpcgen.py-cleanup'
* event_rpcgen.py-cleanup:
  event_rpcgen.py: fix arguments-differ
  event_rpcgen.py: fix attribute-defined-outside-init
  event_rpcgen: suppress some warnings to make pylint clean
  Don't accumulate arguments in `Entry.GetTranslation`
  Fix improper string concatenations in lists
  Fix warnings regarding unused variables
  Don't override the `type` built-in
  Call `super` to call methods from the parent class
  Address `no-self-use` issues reported by pylint
  Run the code through the black formatter
  Reformat strings to template
  Add `argparse` support
  Precompile regular expressions
  Use bools instead of ints values where possible
  Rename all global variables to match the PEP8 spec
  Handle file pointers with context suite patterns
  Iterate over `tokens` with a for instead of while
  Fix indentation for `RpcGenError`
  Don't override `file` built-in
  Resolve variable name issues per PEP8
  Sort imports per PEP8

(cherry picked from commit dd02ad9544ec857412e8a5a0462ddcb29e8045f6)
2020-06-28 21:33:11 +03:00
yuangongji
13af9d263a cmake: replace CheckFunctionExists with CheckSymbolExists
Checking functions with `CheckFunctionExists` may
get wrong results, we should replace it with
`CheckSymbolExists`, which is recommended by the cmake
official documentation.
Before using `CheckSymbolExists`, we use
`CheckIncludeFiles` to check header files and save the
available header files in a variable that guarantees
`CheckSymbolExists` and `CheckTypeSize` to work correctly.
This approach is modeled after the cmake scripts of `curl`.

The following functions or files were not found before
modification, they can now be found:
- msys2 + mingw-8.1.0 on Windows10 or mingw-7.3.0 on Ubuntu-18.04
timerclear
timercmp
timerisset

- windows10
getaddrinfo
getnameinfo
getprotobynumber
getservbyname
putenv
strtoll
timerclear
timercmp
timerisset

- ubuntu-18.04
sys/sysctl.h
timeradd
timerclear
timercmp
timerisset

- MacOS 10.13
sys/random.h
timeradd
timerclear
timercmp
timerisset

(cherry picked from commit 41d1d75a84e03219ec037b0f7982a67fb031eae7)
2020-06-28 21:32:33 +03:00
Mario Emmenlauer
640f9cf6ec LibeventConfig.cmake: restore CMAKE_FIND_LIBRARY_SUFFIXES and LIBEVENT_STATIC_LINK default
The current cmake/LibeventConfig.cmake.in has a few problems and I'm not
sure how cleanly developed it is. It seems rater complex for the little
things I would assume it needs to do.

I found two problems that are fixed in this PR:

- If the downstream user does not explicitly set LIBEVENT_STATIC_LINK
  before calling find_package(libevent) then they will not be able to
  detect the static library, even if its the only one that exists. Since
  this may be rather strict, I've changed the behavior so that
  LIBEVENT_STATIC_LINK can be set to ON or OFF, but if unset, it defaults
  to whatever configuration libevent was built as.

- The other problem is a bug. The package configuration needs to unset
  CMAKE_FIND_LIBRARY_SUFFIXES after use, otherwise all packages that are
  detected after libevent will be "infected" by this setting. This was a
  significant problem for us, and is very hard to detect in downstream
  project, because the order of dependencies will lead to different search
  results.

(cherry picked from commit 1675a55620e6f0bbba5776f2df72cd48920421c2)
2020-06-28 21:32:33 +03:00
yuangongji
dea51c2e11 cmake: fix getaddrinfo checking error
Using `CheckFunctionExists` on Windows to check `getaddrinfo`
will get `not found`, but it actually exists. Using `CheckSymbolExists`
with headers will get correct results. Other functions such as
`getnameinfo`,`inet_ntop`,etc. have the same issue.

(cherry picked from commit 503ba1d36571e3cb01826d15dc462b7d8b5094de)
2020-06-28 21:32:33 +03:00
yuangongji
88384865be cmake: remove CheckFunctionExistsEx
`CheckFunctionExistsEx` is copied from the cmake modules before
3.1.2, which is the minimum required version of libevent.
The internal module `CheckFunctionExists`of cmake can completely
replace it.

(cherry picked from commit 61c5c19bfdabd2f16407a3ed615060c9d0502e82)
2020-06-28 21:32:23 +03:00
yuangongji
b9bf7fa71d autoconf: fix getaddrinfo checking errors on mingw
`AC_CHECK_FUNCS` can not properly check `getaddrinfo` because this
function requires some special headers on mingw.
Using `AC_CHECK_DECL` can effectively solve this issue.

Same for
- getnameinfo
- getprotobynumber
- getservbyname
- inet_ntop
- inet_pton

(cherry picked from commit 6d54be2cc078351b4ce1e469bedc4a976f4e3636)
2020-06-28 21:24:21 +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
yuangongji
30662a3ca9 increase segment refcnt only if evbuffer_add_file_segment() succeeds
(cherry picked from commit 114b3836755f1e526e658b248464465136bd87b8)
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
chenguolong
2e9ceb1655 event_base_once: fix potential null pointer threat
supposing if base is null, EVBASE_ACQUIRE_LOCK and EVBASE_RELEASE_LOCK
would get a coredump, so we add a guard for protection.

Signed-off-by: chenguolong <cgl.chenguolong@huawei.com>
(cherry picked from commit 968bbd5c918568eb95b493af05c464ddfc36671b)
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
8a9b565501 Do not use shared global structures on CYGWIN
Fixes: #950
(cherry picked from commit 2c473056abdf710b6c476b7b19777d5313e71d8a)
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
677378ea42 cmake: do not print used method (EVENT_SHOW_METHOD) while running tests
autotools don't, plus this will make CI logs cleaner

(cherry picked from commit f8a6f12712e775720b36e0c4375a5fd6870bb737)
2020-06-28 21:20:52 +03:00