4110 Commits

Author SHA1 Message Date
Azat Khuzhin
a1293bd2e6
Preserve ET bit for backends with changelist 2018-10-31 01:21:07 +03:00
Isidor Kouvelas
b77d3e787b
Epoll ET setting lost with multiple events for same fd
After two or more events have been registered for the same file
descriptor using EV_ET, if one of the events is deleted, then the
epoll_ctl() call issued by libevent drops the EPOLLET flag resulting in
level triggered notifications.

[ azat: use existing "et" in the evmap_io_del_() ]
2018-10-31 01:21:07 +03:00
Isidor Kouvelas
77c0e51058
Cover ET with multiple events for same fd
[ azat: test cleanup ]
2018-10-31 01:21:07 +03:00
Azat Khuzhin
aa07cbac64
Add ET flag into event_base_dump_events() 2018-10-31 01:21:07 +03:00
Azat Khuzhin
e17e1ee91d
appveyor: reconfigure tests with allow_failure and fast_finish 2018-10-28 21:24:44 +03:00
Azat Khuzhin
fb8666453c
Merge branch 'win32-visibility-event_debug_logging_mask_'
* win32-visibility-event_debug_logging_mask_:
  Introduce EVENT_VISIBILITY_WANT_DLLIMPORT
  regress_http: use TT_BLAZER() over event_debug()

Fixes: #702
2018-10-28 19:48:37 +03:00
Azat Khuzhin
9cba915ee8
Introduce EVENT_VISIBILITY_WANT_DLLIMPORT
And use it in places where event_debug() should be called (since it
requires access to "event_debug_logging_mask_" and in win32 it is
tricky).

One of this places that is covered by this patch is the test for
event_debug().
2018-10-28 19:45:57 +03:00
Azat Khuzhin
5cfb612087
regress_http: use TT_BLAZER() over event_debug()
Later is pretty tricky due to exporting event_debug_logging_mask_ symbol
for win32.
2018-10-28 19:45:52 +03:00
Azat Khuzhin
23e79fd764
Check existence of IPV6_V6ONLY in evutil_make_listen_socket_ipv6only() (mingw32)
MinGW 32-bit 5.3.0 does not defines it and our appveyour [1] build
reports this instantly:
    evutil.c: In function 'evutil_make_listen_socket_ipv6only':
    evutil.c:392:40: error: 'IPV6_V6ONLY' undeclared (first use in this function)
      return setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void*) &one,

  [1]: https://www.appveyor.com/docs/windows-images-software/#mingw-msys-cygwin

Another solution will be to use mingw64 which has it, but I guess we do
want that #ifdef anyway.
2018-10-28 18:39:20 +03:00
Azat Khuzhin
931ec23702
Convert evbuffer_strspn() (internal helper) to use size_t
As pointed by @yankeehacker in #590:
  Signed to Unsigned Conversion Error - buffer.c:1623

  Description: This assignment creates a type mismatch by populating an
  unsigned variable with a signed value. The signed integer will be
  implicitly cast to an unsigned integer, converting negative values into
  positive ones. If an attacker can control the signed value, it may be
  possible to trigger a buffer overflow if the value specifies the length
  of a memory write.

  Remediation: Do not rely on implicit casts between signed and unsigned
  values because the result can take on an unexpected value and violate
  weak assumptions made elsewhere in the program.

Fixes: #590
2018-10-28 16:50:36 +03:00
Azat Khuzhin
f83ac92da9
buffer: add an assert for last_with_datap to suppress static analyzer
../buffer.c:2231:6: warning: Access to field 'flags' results in a dereference of a null pointer
          if (CHAIN_SPACE_LEN(*firstchainp) == 0) {
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../buffer.c:130:30: note: expanded from macro 'CHAIN_SPACE_LEN'
  #define CHAIN_SPACE_LEN(ch) ((ch)->flags & EVBUFFER_IMMUTABLE ? \
2018-10-28 15:24:11 +03:00
Mike Frysinger
731469b33a
libevent.pc: link against core/extra
Since we want people to stop using -levent, have the pkg-config file
also stop linking against that.  This makes it easier to delete the
libevent.so library entirely.

Closes: #141
2018-10-28 03:09:47 +03:00
Azat Khuzhin
fb42e0fac6
bench_cascase: include getopt.h only for _WIN32 (like in other places)
Fixes: #561
2018-10-28 02:00:58 +03:00
Maya Rashish
99a3887d66
Define __EXT_POSIX2 for QNX
POSIX 1003.2 extension is necessary for getopt interface.
Reported here [1] (not mine, I can't test)

  [1]: https://mail-index.netbsd.org/pkgsrc-users/2017/09/20/msg025601.html

Closes: #563 (cherry-pick)
2018-10-28 01:59:11 +03:00
Azat Khuzhin
9fe952a0ae
regress_ssl: reset static variables on test setup/cleanup and eliminate leaks
One tricky bit is reply to the BIO_C_GET_FD command, since otherwise it
will try to close(0) and accepted bev in ssl/bufferevent_connect_sleep
will leak. Other seems more or less trivial.

This was done to make sure that for at least generic cases does not
leak (tricky cases was listed here nmathewson/Libevent#83).

And this will allow run ssl/.. with --no-fork
2018-10-28 01:25:43 +03:00
Azat Khuzhin
7cec9b95a3
test: export basic_test_setup/basic_test_cleanup to extend them 2018-10-28 01:21:35 +03:00
Azat Khuzhin
5264c03f8a
travis-ci: do not notify irc.oftc.net#libevent
I think that this just introduce noise that people just turns off. So
very questionable let's remove it.
2018-10-28 01:21:35 +03:00
Azat Khuzhin
acf09c00e2
be_openssl: avoid leaking of SSL structure
From nmathewson/Libevent#83 by @fancycode:
  There are a few code paths where the passed SSL object is not released in error cases, even if BEV_OPT_CLOSE_ON_FREE is passed as option while for others it is released. That way it's impossible for the caller to know it he has to free it on errors himself or not.

  Line numbers are from "bufferevent_openssl.c" in 911abf3:

  L1414 ("underlying == NULL" passed)
  L1416 (bio could not be created)
  L1446 (different fd passed)
  L1325 (both underlying and fd passed)
  L1328 (out-of-memory)
  L1333 ("bufferevent_init_common_" failed)
  In all error cases after the "bufferevent_ops_openssl" has been assigned, the option is evaluated on "bufferevent_free" (L1399) and the SSL object released (L1226).

Fixes: nmathewson/Libevent#83
2018-10-27 19:30:11 +03:00
Azat Khuzhin
474d72aeac
be_openssl: drop close_flag parameter of the BIO_new_bufferevent() 2018-10-27 18:29:57 +03:00
Azat Khuzhin
26ef859aa7
Add evhttp_parse_query_str_flags()
And a set of flags:
- EVHTTP_URI_QUERY_LAST
- EVHTTP_URI_QUERY_NONCONFORMANT

Fixes: #15
2018-10-27 17:59:11 +03:00
Azat Khuzhin
d161ec3842
regress_http: basic evhttp_parse_query_str() coverage 2018-10-27 17:58:12 +03:00
Azat Khuzhin
8348b41308
cmake: add various warning flags like autotools has
This is mostly to match autotools and reduce amount mixiing declarations
and code.

Added:
- -Wextra (the same as -W), -Wno-unused-parameter -Wstrict-aliasing
- -fno-strict-aliasing (gcc 2.9.5+)
- -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement (4.0+)
- -Waddress -Wno-unused-function -Wnormalized=id -Woverride-init (4.2+)
- -Wlogical-op (4.5+)

Removed:
- -Wformat (include in -Wall)

Plus use CMAKE_C_COMPILER_ID over CMAKE_COMPILER_IS_GNUCC, as
cmake-variables(7) suggesting, and add common GNUC/CLANG variables.

v2: drop checks for flags, since add_compiler_flags() will check if such
flags exists anyway (but just to note, gcc ignores non existing warning
flags by default).
2018-10-27 17:12:53 +03:00
Azat Khuzhin
006c528a21
autotools: do not add warnings that is included into -Wall already
Plus remove duplicates
2018-10-27 16:52:56 +03:00
Murat Demirten
387d91f9ab
listener: ipv6only socket bind support
According to RFC3493 and most Linux distributions, default value is to
work in IPv4-mapped mode. If there is a requirement to bind same port
on same ip addresses but different handlers for both IPv4 and IPv6,
it is required to set IPV6_V6ONLY socket option to be sure that the
code works as expected without affected by bindv6only sysctl setting
in system.

See an example working with this patch:
https://gist.github.com/demirten/023008a63cd966e48b0ebcf9af7fc113

Closes: #640 (cherry-pick)
2018-10-26 07:24:29 +03:00
Azat Khuzhin
b2667b7696
Merge branch 'evutil_found_ifaddr-dev'
* evutil_found_ifaddr-dev:
  Cover evutil_v4addr_is_local_()/evutil_v6addr_is_local_()
  Split evutil_found_ifaddr() into helpers (evutil_v{4,6}addr_is_local())
  Use INADDR_ANY over 0 in evutil_found_ifaddr()
  Replace EVUTIL_V4ADDR_IS_*() macroses with static inline functions
  Filter link-local IPv4 addresses in evutil_found_ifaddr()
2018-10-25 00:50:50 +03:00
Azat Khuzhin
32349ab6f4
Cover evutil_v4addr_is_local_()/evutil_v6addr_is_local_() 2018-10-25 00:49:46 +03:00
Azat Khuzhin
6966d39f38
Split evutil_found_ifaddr() into helpers (evutil_v{4,6}addr_is_local()) 2018-10-25 00:49:45 +03:00
Azat Khuzhin
d5f85257b7
Use INADDR_ANY over 0 in evutil_found_ifaddr() 2018-10-25 00:09:03 +03:00
Azat Khuzhin
ab406fca30
Replace EVUTIL_V4ADDR_IS_*() macroses with static inline functions
Macros over static inline over and over again:
- readability
- type safety
2018-10-25 00:08:38 +03:00
Azat Khuzhin
117dc92129
Filter link-local IPv4 addresses in evutil_found_ifaddr()
Fixes: #668
2018-10-25 00:06:47 +03:00
Azat Khuzhin
0ec12bc84c
Merge branch 'http-request-line-parsing'
* http-request-line-parsing:
  Fix http https_basic/https_filter_basic under valgrind (increase timeout)
  http: cover various non RFC3986 conformant URIs
  http: allow non RFC3986 conformant during parsing request-line (http server)
  http: do not try to parse request-line if we do not have enough bytes
  http: allow trailing spaces (and only them) in request-line (like nginx)
  http: cleanup of the request-line parsing
2018-10-23 00:12:23 +03:00
Azat Khuzhin
5f1b4dfa02
Fix http https_basic/https_filter_basic under valgrind (increase timeout) 2018-10-23 00:12:10 +03:00
Azat Khuzhin
15bfe712a7
http: cover various non RFC3986 conformant URIs
- http/basic_trailing_space -- covers cases when there is trailing space
  after the request line (nginx handles this)
- http/simple_nonconformant -- covers non RFC3986 conformant URIs
2018-10-23 00:12:10 +03:00
Azat Khuzhin
b94d913d90
http: allow non RFC3986 conformant during parsing request-line (http server)
Reported-by: lsdyst@163.com
2018-10-23 00:12:03 +03:00
Azat Khuzhin
64ead341a0
http: do not try to parse request-line if we do not have enough bytes 2018-10-22 23:56:50 +03:00
Azat Khuzhin
254fbc81b4
http: allow trailing spaces (and only them) in request-line (like nginx) 2018-10-22 23:56:31 +03:00
Azat Khuzhin
6cf659b0bd
http: cleanup of the request-line parsing 2018-10-22 23:55:35 +03:00
Azat Khuzhin
2f43d1d409
Disable parallel jobs for the osx (due to CPU time deficit) in travis-ci
As you can see right now linux workers has zero failed tests, while osx
workers has 18 failed tests:
  [bufferevent_connect_hostname_emfile FAILED]
  [bufferevent_pair_release_lock FAILED]
  [bufferevent_timeout FAILED]
  [bufferevent_timeout_filter FAILED]
  [bufferevent_timeout_pair FAILED]
  [common_timeout FAILED]
  [del_wait FAILED]
  [immediatesignal FAILED]
  [loopexit FAILED]
  [loopexit_multiple FAILED]
  [monotonic_res FAILED]
  [no_events FAILED]
  [persistent_active_timeout FAILED]
  [persistent_timeout_jump FAILED]
  [signal_switchbase FAILED]
  [signal_while_processing FAILED]
  [simpletimeout FAILED]
  [usleep FAILED]

And this patch should remove from this list time related failures
(though maybe not all of them).
2018-10-22 01:11:03 +03:00
Azat Khuzhin
5d3e8c15e7
Use matrix.fast_finish for the travis-ci to mark the build ASAP
AFAIR there is shortage of osx workers on travis-ci, IOW builds that
requires them can wait fair amount of time in the queue by just waiting.

Plus linux workers AFAICS can run multiple jobs in parallel (4-5), while
osx does not.

Hence if we do allow failures for osx (and right now they have a lot of
failed tests) let's mark build result based on tests under linux only.

So in a nut shell this will reduce build time from 5 hours to 20-30
minutes.
2018-10-22 01:10:17 +03:00
Azat Khuzhin
6ac8e775bb
Simplify bufferevent timeout tests to reduce CPU usage in between start/compare
Between start (setting "started_at") and comparing the time when
timeouts triggered with the start (test_timeval_diff_eq), there is too
much various things that can introduce extra delays and eventually could
fail the test on machine with shortage of CPU.

And this is exactly what happend on:
- travis-ci
- #262

Here is a simple reproducer that I came up with for this issue:
  docker run --cpus=0.01 -e LD_LIBRARY_PATH=$PWD/lib -e PATH=/usr/bin:/bin:$PWD/bin -v $PWD:$PWD --rm -it debian:testing regress --no-fork --verbose bufferevent/bufferevent_timeout

Under limited CPU (see reproducer) the test almost always has problems
with that "write_timeout_at" exceed default timeval diff tolerance
(test_timeval_diff_eq() has 50 tolerance), i.e.:
  FAIL ../test/regress_bufferevent.c:1040: assert(labs(timeval_msec_diff(((&started_at)), ((&res1.write_timeout_at))) - (100)) <= 50): 101 vs 50

But under some setup write timeout can even not triggered, and the
reason for this is that we write to the bufferevent 1024*1024 bytes, and
hence if evbuffer_write_iovec() will has some delay after writev() and
not send more then one vector at a time [1], it is pretty simple to
trigger, i.e.:
  FAIL ../test/regress_bufferevent.c:1040: assert(labs(timeval_msec_diff(((&started_at)), ((&res1.write_timeout_at))) - (100)) <= 50): 1540155888478 vs 50

  [1]: https://gist.github.com/azat/b72773dfe7549fed865d439e03de05c1

So this patch just send static small payload for all cases (plus a few
more asserts added).

The outcome of this patch is that all regression tests passed on
travis-ci for linux box [2]. While before it fails almost always [3].
Also reproducer with CPU limiting via docker also survive some
iterations (and strictly speaking it should has less CPU then travis-ci
workers I guess).

  [2]: https://travis-ci.org/azat/libevent/builds/444391481
  [3]: https://travis-ci.org/libevent/libevent/builds/444336505
2018-10-22 00:53:07 +03:00
Bogdan Harjoc
3e6553a180
evdns: handle NULL filename explicitly
Otherwise we will try to open NULL filename and got EFAULT and anyway
will got the same return code from evdns_base_resolv_conf_parse_impl()

Closes: #680 (cherry-picked)
2018-10-21 14:28:59 +03:00
Azat Khuzhin
fb090aa622
Revert "travis-ci: use travis_retry to reduce number of problems with flacky tests"
That was a bad idea, because all this patch did is just uses extra CPU
time on travis-ci workers and eventually fail the build anyway.

It also increases time of executing one matrix entry (x3).

This reverts commit 7004ee8e869faabe3a284fb3d7eb859fb50ef90c.
2018-10-21 03:19:53 +03:00
Azat Khuzhin
bd2184d8d4
Merge branch 'regress-dns-fixes'
* regress-dns-fixes:
  Do not rely on getservbyname() for most of the dns regression tests
  Turn off dns/getaddrinfo_race_gotresolve by default
  Fix an error for debug locking in dns/getaddrinfo_race_gotresolve
2018-10-21 03:15:34 +03:00
Azat Khuzhin
2cb8eae795
Do not rely on getservbyname() for most of the dns regression tests
There is only one test that uses service name getaddrinfo_async, which
manually check whether it works or not, other should not assume that it
is available and works.

There was already an attempt to overcome some possible limitations, like
lack of "http" in /etc/services in
d6bafbbeb27ff3943d6f3b6783bcded76384c31e ("test/dns: replace servname
since solaris does not have "http"")
2018-10-21 03:12:24 +03:00
Azat Khuzhin
7198bbb8f1
Turn off dns/getaddrinfo_race_gotresolve by default
It is:
- pretty internal regression
- CPU bound
- right now failed on travis-ci machines
2018-10-21 03:11:00 +03:00
Azat Khuzhin
09c74f7121
Fix an error for debug locking in dns/getaddrinfo_race_gotresolve
When there is no /etc/services file evdns_getaddrinfo() will fail (with
service="ssh") and hence it will go to then "end" label with locked
rp.lock which in case of debug locking checks will bail with:
  [err] ../evthread.c:220: Assertion lock->count == 0 failed in debug_lock_free

So add rp.locked flag, and unlock the lock before freeing it if it is in
locked state.

And here is how you can reproduce the issue:
  $ docker run -e LD_LIBRARY_PATH=$PWD/lib -e PATH=/usr/bin:/bin:$PWD/bin -v $PWD:$PWD --rm -it debian:testing regress dns/getaddrinfo_race_gotresolve
(since debian:testing does not have /etc/services)
2018-10-21 03:10:12 +03:00
Jiri Luznicky
95918754d2
Fix missing LIST_HEAD
Despite the presence of 'sys/queue.h' in some stdlib implementations
(i.e. uclibc) 'LIST_HEAD' macro can be missing.  This fix defines this
macro in the same manner as was done previously for 'TAILQ_'.

Fixes: #539
Closes: #639 (cherry-picked)
Backport: 2.1.9
2018-10-20 03:05:53 +03:00
Azat Khuzhin
4c61a04cd5
Make cmake's check_const_exists() rely on cache 2018-10-18 23:16:05 +03:00
Azat Khuzhin
878bb2d3b9
Merge branch 'be-wm-overrun-v2'
* be-wm-overrun-v2:
  Fix hangs due to watermarks overruns in bufferevents implementations
  test: cover watermarks (with some corner cases) in ssl bufferevent

Fixes: #690
2018-10-17 23:21:32 +03:00
Azat Khuzhin
5a455acd3b
Fix hangs due to watermarks overruns in bufferevents implementations
Some implementations of bufferevents (for example openssl) can overrun
read high watermark.
And after this if user callback will not drain enough data it will be
suspended (i.e. it will not be runned again anymore).
This is not the expecting behaviour as one may guess, since in this case
the data will never be read. Hence once we detected that the watermark
exceeded (even after calling user callback) we will schedule the
callback again.

This also can be fixed in bufferevent openssl implementation (by
strictly limiting how much data is added to the read buffer according to
read high watermark), but since this data is already available (and in
memory) there is no point in doing so.
2018-10-17 23:21:17 +03:00