4614 Commits

Author SHA1 Message Date
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
chenguolong
968bbd5c91 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>
2020-02-16 02:54:15 +03:00
yuangongji
5fbe6313ae test-ratelim: add missing free 2020-02-12 22:10:31 +08:00
yangyongsheng
08e7d5136d misspelling of output in bufferevent_struct.h 2020-01-28 14:31:39 +08:00
Azat Khuzhin
0b6f29aca6 Merge branch 'github-actions-v2' (#951)
* github-actions-v2:
  travis: disable doxygen and coveralls, in favor of github actions
  github actions: test and coverage
  github actions: doxygen
  Ignore truthy in yamllint (for github-actions)
  test: mark common_timeout as retriable
  cmake: set rpath for libraries on linux
  test-export: compatible with all versions of visual studio
  coverage: 'lcov --remove' need full path
2020-01-27 01:56:58 +03:00
Azat Khuzhin
19a55164f0 travis: disable doxygen and coveralls, in favor of github actions 2020-01-27 01:53:27 +03:00
yuangongji
84bb2c18e4 github actions: test and coverage 2020-01-27 01:50:13 +03:00
yuangongji
d151968fe7 github actions: doxygen 2020-01-27 01:50:13 +03:00
Azat Khuzhin
cf379ecc49 Ignore truthy in yamllint (for github-actions) 2020-01-26 21:37:11 +03: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
yuangongji
ce8be2385b cmake: set rpath for libraries on linux 2020-01-24 07:52:06 +03:00
yuangongji
9adc9f1496 test-export: compatible with all versions of visual studio 2020-01-24 07:52:06 +03:00
yuangongji
1a99f9b25c coverage: 'lcov --remove' need full path 2020-01-24 07:52:06 +03:00
Azat Khuzhin
2c473056ab Do not use shared global structures on CYGWIN
Fixes: #950
2020-01-24 07:51:19 +03:00
JackBoosY
ec775a960b Add vcpkg installation instructions 2020-01-21 22:03:37 -08:00
Azat Khuzhin
ca2b72c546 test: move thread into realtime class even on EVENT__DISABLE_THREAD_SUPPORT 2020-01-14 21:58:16 +03:00
Azat Khuzhin
d0adbc0565 test: fix compilation without thread support (EVENT__DISABLE_THREAD_SUPPORT=ON) 2020-01-14 10:20:27 +03:00
Azat Khuzhin
8dcccf35c2 travis-ci: do not allow failures under osx 2020-01-14 02:36:54 +03:00
Azat Khuzhin
30fe125041 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().
2020-01-14 02:36:39 +03:00
Azat Khuzhin
10504fcab9 test: fix dst thread in move_pthread_to_realtime_scheduling_class (osx)
Fixes the following tests on osx:
- del_wait
- no_events

Refs: #940
2020-01-14 02:07:22 +03:00
Azat Khuzhin
34d51e1bc9 test: fix compilation under win32 (rearrange thread_setup() code) 2020-01-14 01:44:06 +03:00
Azat Khuzhin
391003e9b7 test: use THREAD_* wrappers over pthread* in del_notify 2020-01-14 00:42:13 +03:00
Azat Khuzhin
a6f81aa454 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
2020-01-13 23:36:40 +03:00
Azat Khuzhin
4b72024b7f test: Use THREAD_* wrappers in del_notify/del_wait 2020-01-13 23:36:19 +03:00
Azat Khuzhin
e6285eed62 test: move threads created with THREAD_START() to realtime scheduling class too 2020-01-13 23:36:19 +03:00
Azat Khuzhin
b1e46c32db test: put thread into real time scheduling class on osx for better latencies 2020-01-13 23:36:19 +03:00
Azat Khuzhin
603d7937d2 Merge branch 'ci-improvements'
* ci-improvements:
  travis-ci: measure build/tests time
  travis-ci: drop travis_wait (does not work with sub processes)
  cmake: do not print used method (EVENT_SHOW_METHOD) while running tests
  cmake: run regress test quietly like autotools (makes CI logs cleaner)
2020-01-13 22:27:32 +03:00
Azat Khuzhin
b30717eb23 travis-ci: measure build/tests time 2020-01-13 22:26:37 +03:00
Azat Khuzhin
fbe6f7d92a travis-ci: drop travis_wait (does not work with sub processes)
Refs: https://github.com/travis-ci/travis-ci/issues/8526
2020-01-13 22:26:37 +03:00
Azat Khuzhin
f8a6f12712 cmake: do not print used method (EVENT_SHOW_METHOD) while running tests
autotools don't, plus this will make CI logs cleaner
2020-01-13 22:26:37 +03:00
Azat Khuzhin
fa33819e3b cmake: run regress test quietly like autotools (makes CI logs cleaner) 2020-01-13 22:26:37 +03:00
nntrab
02905413fd Add callback support for error pages
The existing error pages are very basic and don't allow for
multi-lingual support or for conformity with other pages in a web site.
The aim of the callback functionality is to allow custom error pages to
be supported for calls to evhttp_send_error() by both calling
applications and Libevent itself.

A backward-incompatible change has been made to the title of error pages
sent by evhttp_send_error(). The original version of the function used
the reason argument as part of the title. That might have unforeseen
side-effects if it contains HTML tags. Therefore the title has been
changed to always use the standard status text.

An example of the error callback can be found in this
[version](https://github.com/libevent/libevent/files/123607/http-server.zip)
of the 'http-server' sample. It will output error pages with very bright
backgrounds, the error code using a very large font size and the reason.

Closes: #323 (cherr-picked from PR)
2020-01-13 00:50:14 +03:00
Azat Khuzhin
462f2e9766 Merge branch 'http-connect'
After this patchset http-connect works with pproxy [1]:

    $ pproxy -l http://:8000/ -vvv &
    $ http-connect //127.1:8000 http://kernel.org:80/

  [1]: https://pypi.org/project/pproxy/

* http-connect:
  http-connect: do not check connection on GET cb
  http-connect: set Host header (for CONNECT and GET) (like curl)
  http-connect: cleanup and helpers
  http: do not close connection for CONNECT
  http: do not assume body for CONNECT

Fixes: #946
2020-01-12 15:35:10 +03:00
Azat Khuzhin
9c91fe1479 http-connect: do not check connection on GET cb 2020-01-12 15:34:01 +03:00
Azat Khuzhin
415ddee337 http-connect: set Host header (for CONNECT and GET) (like curl) 2020-01-12 15:34:01 +03:00
Azat Khuzhin
e54d5fc57c http-connect: cleanup and helpers 2020-01-12 15:34:01 +03:00
Azat Khuzhin
12ad0c8fcd http: do not close connection for CONNECT 2020-01-12 15:34:01 +03:00
Azat Khuzhin
998e68340e http: do not assume body for CONNECT 2020-01-12 15:33:59 +03:00
Dimo Markov
f0e79bafd8 Added uninstall target check to cmakelists 2020-01-08 20:37:16 +02:00
Azat Khuzhin
08981f8d75 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
2020-01-07 22:15:08 +03:00
yuangongji
6412f34f24 evutil_time: Implements usleep() using wait funtion on Windows 2019-12-31 00:37:29 +03:00
yangyongsheng
1edb6f6188 Initialize variable to 0 replace use memset function in sample/hello-world.c 2019-12-30 10:09:15 +08:00
Azat Khuzhin
ea12428db6 appveyor: switch to Previous Visual Studio 2019 (VS issues after update)
After update [1] of the Visual Studio 2019 image cmake unable to find
path to the c compiler [2]:

    cmake : CMake Error at CMakeLists.txt:47 (project):
    At line:1 char:1
    + cmake -G 'Visual Studio 16 2019' -A x64 ..
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CMake Error at ...t:47 (project)::String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError

      The CMAKE_C_COMPILER:
        C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
      is not a full path to an existing compiler tool.

  [1]: https://github.com/appveyor/ci/issues/3231
       https://www.appveyor.com/updates/2019/12/09/
  [2]: https://ci.appveyor.com/project/libevent/libevent/builds/29431286/job/a68h7dn9rcride9g
2019-12-10 09:29:08 +03:00
Andre Pereira Azevedo Pinto
f76456b0dc Add support for priority inheritance
Add support for posix mutex priority inheritance. This is important to
avoid priority inversion in systems running with threads with different
priorities.

Signed-off-by: Andre Azevedo <andre.azevedo@gmail.com>
2019-12-09 14:55:31 -08:00
Azat Khuzhin
8f13c170cf cmake: set CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY they are not defined
This will allow overriding them in parent cmake rules, i.e. if libevent
is used via add_subdirectory().

Closes: #931
2019-11-30 15:58:17 +03:00
Azat Khuzhin
b9f442e2d7 cmake: use CMAKE_LIBRARY_OUTPUT_DIRECTORY for the final shared library symlink
Fixes: 669a53f3 ("cmake: set library names to be the same as with autotools")
2019-11-30 15:54:56 +03:00
Azat Khuzhin
aff231229e appveyor: fix EVENT_CMAKE_OPTIONS expansion (for multiple arguments)
Fixes: 63f73ee2 ("CI: integrate testing for components export")
2019-11-17 23:31:14 +03:00
Azat Khuzhin
8a34869984 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
2019-11-17 20:52:28 +03:00
Azat Khuzhin
026590f908 mailmap: add name/email aliases for yuangongji (name and email)
Before:
  $ git log --format='%aE %aN' --author=yuangongji | sort | uniq -c
       30 82787816@qq.com yuangongji
        1 82787816@qq.com yuangongji (A)

After:
  $ git log --format='%aE %aN' --author=yuangongji | sort | uniq -c
       34 yuangongji@foxmail.com yuangongji
2019-11-17 15:51:07 +03:00
Azat Khuzhin
8be8ac4602 Merge #929 -- cmake package improvements
Example:

  find_package(Libevent 2.2.0 REQUIRED COMPONENTS core)
  add_executable(test test.c)
  target_link_libraries(test ${LIBEVENT_LIBRARIES})

* upstream/pr/929:
  CI: integrate testing for components export
  cmake: test for find_package()
  cmake: improve package config file
2019-11-17 02:45:54 +03:00