4869 Commits

Author SHA1 Message Date
Azat Khuzhin
e5941b2ce9 Drop unused le_ssl_ops::err_is_ok
It is not used anymore since errors are ignored if some progress had
been done.
2023-05-16 21:20:21 +02:00
Thuan Tran
ef51444f43 More SSL_read() to fill big buffer
Once SSL_read() only get max 16K bytes (one TLS record).
In case of big buffer, should more SSL_read() to fill the buffer.

Using sample https-client to measure max income MBit/s via nload tool.
Note: set bufferevent_set_max_single_read() by 32K and add the chunk
callback to read out each piece of data.

The client sample do https request a data 900KB (the server don't use
Transfer-Encoding: chunked)
- With origin/master: max income is 2.26 MBit/s
  The chunk callback never get a piece of data > 16K.
- With this PR: max income is 2.44 MBit/s
  The chunk callback can get some piece of data 32K or more.
2023-05-16 21:11:54 +02:00
Thuan Tran
4ab3242da1 Make bufferevent_set_max_single_read() effect 2023-05-16 21:11:54 +02:00
Ingo Bauersachs
acfac7ae4a Make dependency paths relocatable
The generated configurations for both CMake and pkg-config included
absolute paths to dependencies (OpenSSL, MbedTLS). This is contrary
to the general CMake advise to create relocatable packages [1].

Additionally, when building both mbedtls and libevent via CMake's
FetchContent in the same project, loading the project would fail with

  INTERFACE_INCLUDE_DIRECTORIES property contains path:
    "/home/user/project/cmake-build/_deps/mbedtls-build/include"
  which is prefixed in the source directory.

The required changes include:
- Adding the outer includes only to the BUILD_INTERFACE solves the
  makes the CMake paths relocatable and thus solves the FetchContent
  problem.
- Updates to libevent_*.pc.in fixes the relocatable issues for
  pkg-config and properly declares currently missing dependencies.
- Using components for linking to OpenSSL (requiring CMake 3.4)
  and MbedTLS. The new MbedTLS target names now match the component
  names of the MbedTLS' CMake project.
- Use the Threads CMake library reference instead of a direct
  reference to support both built-in pthread and -lpthread.

v2 (azat): get back CMAKE_REQUIRED_LIBRARIES

[1] https://cmake.org/cmake/help/v3.25/manual/cmake-packages.7.html#creating-relocatable-packages
2023-05-16 07:46:56 +02:00
Jeremy W. Murphy
81c6b8823c
cmake: Only use relative paths for install DESTINATION option (#1405)
As described in #1404, the explicit use of CMAKE_INSTALL_PREFIX conflicts with using command-line --prefix.

This simply removes all explicit use of CMAKE_INSTALL_PREFIX.

Otherwise this path will be duplicated:

    $ cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=inst ..
    $ DESTDIR=inst ninja install
    ...
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/util.h
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/ws.h
    ...

Fixes: #1404
Co-authored-by: Jeremy Murphy <jeremymu@blackmagicdesign.com>
2023-05-15 21:07:36 +02:00
Azat Khuzhin
4dee61c02c Merge remote-tracking branch 'upstream/pr/1397' - #1397
* upstream/pr/1397:
  Make sure exported include dirs are correct
  Fix Configure_RPATH()
  Install LibeventConfig.cmake similar to other cmake files
  Use GNUInstallDirs for mapping installation directories
2023-05-14 22:56:02 +02:00
Tobias Mayer
16be768dac Make sure exported include dirs are correct
CMake config files don't need any logic to detect the location of
installed headers or DSOs, because these locations are already
determined at project configuration time. They also don't need
to distinguish between build and install trees, because that is
already handled by the generated `LibeventTargets-*.cmake` files.
2023-05-14 22:43:47 +02:00
Azat Khuzhin
41a7393f3e Fix Configure_RPATH() 2023-05-14 22:43:47 +02:00
Jonathan Ringer
be03bf385b Install LibeventConfig.cmake similar to other cmake files
- Don't destroy cmake file between test case invocations
2023-05-14 22:43:47 +02:00
Jonathan Ringer
1f1593ff27 Use GNUInstallDirs for mapping installation directories 2023-05-14 22:43:47 +02:00
Azat Khuzhin
fe610f2cdc Fix util/mm_calloc_enomem under FreeBSD
It looks like the compiler optimizes this call out with tt_assert():

    (gdb) disas /m test_event_calloc_enomem
    Dump of assembler code for function test_event_calloc_enomem:
       0x0000000000293bb0 <+0>:     push   %rbp
       0x0000000000293bb1 <+1>:     mov    %rsp,%rbp
       0x0000000000293bb4 <+4>:     call   0x29f510 <__error@plt>
       0x0000000000293bb9 <+9>:     movl   $0x0,(%rax)
       0x0000000000293bbf <+15>:    call   0x2990e0 <tinytest_set_test_failed_>
       0x0000000000293bc4 <+20>:    mov    $0x2168e4,%edi
       0x0000000000293bc9 <+25>:    mov    $0x220582,%esi
       0x0000000000293bce <+30>:    mov    $0x20d893,%edx
       0x0000000000293bd3 <+35>:    mov    $0x53a,%ecx
       0x0000000000293bd8 <+40>:    xor    %eax,%eax
       0x0000000000293bda <+42>:    call   0x29f3b0 <printf@plt>
       0x0000000000293bdf <+47>:    mov    $0x20da72,%edi
       0x0000000000293be4 <+52>:    mov    $0x20f731,%esi
       0x0000000000293be9 <+57>:    xor    %eax,%eax
       0x0000000000293beb <+59>:    pop    %rbp
       0x0000000000293bec <+60>:    jmp    0x29f3b0 <printf@plt>

While with tt_ptr_op() it does not:

    (gdb) disas /m test_event_calloc_enomem
    Dump of assembler code for function test_event_calloc_enomem:
       0x0000000000293bd0 <+0>:     push   %rbp
       0x0000000000293bd1 <+1>:     mov    %rsp,%rbp
       0x0000000000293bd4 <+4>:     push   %rbx
       0x0000000000293bd5 <+5>:     push   %rax
       0x0000000000293bd6 <+6>:     call   0x29f610 <__error@plt>
       0x0000000000293bdb <+11>:    movl   $0x0,(%rax)
       0x0000000000293be1 <+17>:    mov    $0xffffffffffffffff,%rdi
       0x0000000000293be8 <+24>:    mov    $0xffffffffffffffff,%rsi
       0x0000000000293bef <+31>:    call   0x2a01c0 <calloc@plt>
       0x0000000000293bf4 <+36>:    test   %rax,%rax
       0x0000000000293bf7 <+39>:    je     0x293c2b <test_event_calloc_enomem+91>
2023-05-14 22:35:53 +02:00
Azat Khuzhin
13f5552336 test: add missing include of arpa/inet.h for ntohs in regress_ws.c
This will fix one warning in FreeBSD
2023-05-14 22:31:02 +02:00
Azat Khuzhin
1f006637ec Merge branch 'build/osx-fixes'
* build/osx-fixes:
  Suppress -Wmacro-redefined for htonll/ntohll in OSX
  Fix -Wtautological-constant-out-of-range-compare in regress_http under OSX
2023-05-14 22:03:26 +02:00
Azat Khuzhin
6eba967e1c Suppress -Wmacro-redefined for htonll/ntohll in OSX
OSX:

    test/regress_ws.c:61:9: warning: 'htonll' macro redefined [-Wmacro-redefined]
    #define htonll(x)    \
            ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/sys/_endian.h:141:9: note: previous definition is here
    #define htonll(x)       __DARWIN_OSSwapInt64(x)
            ^
    test/regress_ws.c:65:9: warning: 'ntohll' macro redefined [-Wmacro-redefined]
    #define ntohll(x) htonll(x)
            ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/sys/_endian.h:140:9: note: previous definition is here
    #define ntohll(x)       __DARWIN_OSSwapInt64(x)
            ^
2023-05-14 22:01:18 +02:00
Azat Khuzhin
5f1fc92b13 Fix -Wtautological-constant-out-of-range-compare in regress_http under OSX
compiler warning:

    test/regress_http.c:968:38: warning: result of comparison of constant 65536 with expression of type 'enum evhttp_cmd_type' is always true [-Wtautological-constant-out-of-range-compare]
            if (evhttp_request_get_command(req) != EVHTTP_REQ_CUSTOM) {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~
2023-05-14 21:55:43 +02:00
Dmitry Antipov
d19690980d Silence weird GCC warning about an uninitialized variable
For the CMake release build with -DEVENT__ENABLE_GCC_WARNINGS=ON
and -DEVENT__DISABLE_MM_REPLACEMENT=ON, GCC version 11 and 12 may
complain about possibly uninitialized variable:

In function ‘event_debug_assert_not_added_’,
    inlined from ‘event_assign’ at event.c:2184:2,
    inlined from ‘event_new’ at event.c:2276:6:
cc1: error: ‘ev’ may be used uninitialized [-Werror=maybe-uninitialized]
event.c: In function ‘event_new’:
event.c:361:13: note: by argument 1 of type ‘const struct event *’ to  event_debug_assert_not_added_.part.0’ declared here
  361 | static void event_debug_assert_not_added_(const struct event *ev)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This warning is most likely a false positive and can be silenced
by explicitly disabling inlining for 'event_assign()'.

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2023-05-14 20:42:19 +02:00
Azat Khuzhin
73037f88f9 Ignore any archives (since you may use separate build dir for 'make dist') 2023-05-14 20:32:50 +02:00
Azat Khuzhin
e8cbe7b6e1 Merge branch 'ssl/fix-partial-read' - #1451
* ssl/fix-partial-read:
  ssl: do not triger EOF if some data had been successfully read
  ssl: rename err_is_ok to handshake_is_ok (internal API)
2023-05-14 20:04:44 +02:00
Azat Khuzhin
7652cf4068 ssl: do not triger EOF if some data had been successfully read
Previously in case when evbuffer_reserve_space() returns > 1, but
it was able to read only 1 IO vector, it will try to read the next one,
got 0 (EOF for mbedTLS or SSL_ERROR_ZERO_RETURN for OpenSSL) and will
trigger EOF, while instead, it should trigger EV_READ w/o EOF and only
after EOF.
2023-05-14 16:53:13 +02:00
Azat Khuzhin
6375dcb46d ssl: rename err_is_ok to handshake_is_ok (internal API) 2023-05-14 16:49:18 +02:00
liaotonglang
d06e573c60 style fix: use tab for indent 2023-05-05 22:42:43 +02:00
fanquake
bdb343e180 ci: use newer actions/x versions for master jobs
Now that the jobs are running again, a number of deprecation warnings
have surfaced
https://github.com/libevent/libevent/actions/runs/4876367881:
```bash
Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2.0.0.
```

Looks like the most straightforward thing todo here is just use the
newer version of the checkout action.

Also move to the v1 tag for the coveralls job, rather than a pinned,
much older version (the latest release is 1.2.5, https://github.com/coverallsapp/github-action/releases).

Same again for actions/cache.
2023-05-04 21:21:40 +02:00
fanquake
211736697b ci: use OpenBSD 7.2 over 7.1
In the most recent CI run, all the OpenBSD CI jobs failed, i.e
https://github.com/libevent/libevent/actions/runs/4876367885/jobs/8699759831,
this seems to be due to the fact that packages for 7.1 have been removed
from https://cdn.openbsd.org/pub/OpenBSD/ (only has 7.2 & 7.3):
```bash
  Config file: openbsd-7.1.conf
  https://cdn.openbsd.org/pub/OpenBSD/7.1/packages/amd64/: no such dir
  Can't find rsync-3.2.3p0
  Couldn't install rsync-3.2.3p0
  exec shell: bash run.sh showDebugInfo
```

Switch to using 7.2, which is available, so that the CI will run.
2023-05-04 21:20:23 +02:00
fanquake
60ad22d47d actions: use supported version of Ubuntu
It looks like these jobs are failing to run, because support for
ubuntu-18.04 has been removed entirely, see:
https://github.com/actions/runner-images/issues/6002.

Migrate to ubuntu-20.04.
2023-05-03 22:43:17 +02:00
fanquake
75208132d5
doc: minor cleanups following #1441 (#1442)
Also fixes 1 broken link (apologies).
2023-04-20 23:33:22 +03:00
Azat Khuzhin
612a74c766
Merge pull request #1441 from fanquake/autoconf_doc_updates
doc: minor autoconf/formatting improvements
2023-04-17 21:19:58 +02:00
fanquake
ac69410e1b
doc: mark Autotools as deprecated in building.md
Re-arrange so CMake is mentioned first.
Formatting improvements.
2023-04-17 14:42:59 +01:00
fanquake
2470b37bd1
doc: move autoconf link in readme to autoconf section. 2023-04-17 14:22:30 +01:00
lilinjie
4c993a0e7b
Fix typo in changelog (#1438) 2023-04-11 06:44:37 +02:00
Azat Khuzhin
f747a7b93b Prohibit VLA in autotools too 2023-04-04 22:19:07 +02:00
Azat Khuzhin
f04d90b121 Fix building with -Wstack-protector due to VLA and fobid them
It is not a thankless task to fix such issues on and on, let's just
prohibit this cases, and our build with -Werror on CI will show new
issues from now on.

Fixes: #1434
2023-04-04 22:17:14 +02:00
fanquake
1878232bd5 build: split kqueue warning message into cross-compile and apple
This is output when compiling (natively) on macOS systems, which is
confusing, because no cross-compilation is involved.

Split the message into separate cases.
2023-04-04 22:04:17 +02:00
zhenhaonong
fc568ff045 Deal with partial writes on SSL write
SSL write may do partial writes in some cases. For example, document
of mbedtls_ssl_write says:
  If the return value is non-negative but less than length, the function
  must be called again with updated arguments: buf + ret, len - ret
  (if ret is the return value) until it returns a value equal to the
  last 'len' argument.

In case of partial writes, we should continue writing the same chain of
buffer, not the next chain.
2023-03-29 06:19:10 +02:00
Liao Tonglang
9203d98ff8
http: style fix: use space between arguments list (#1435) 2023-03-26 22:35:00 +02:00
Azat Khuzhin
6e1826dd77 ci: fix typo in yaml for cifuzz
Follow-up for: #1431
2023-03-08 21:34:37 +01:00
Azat Khuzhin
606056d6e7 ci: switch to ubuntu 20.04
github action reports "internal error" for builds on ubuntu 18.04:

    linux-cmake-job (ubuntu-18.04, COMPILER_CLANG)
    This is a scheduled Ubuntu-18.04 brownout. The Ubuntu-18.04 environment is deprecated and will be removed on April 1st, 2023. For more details, see https://github.com/actions/runner-images/issues/6002

    linux-cmake-job (ubuntu-18.04, COMPILER_CLANG)
    GitHub Actions has encountered an internal error when running your job.
2023-03-07 06:15:33 +01:00
Diogo Teles Sant'Anna
99a4b1a786 ci: set minimal permissions on GitHub Actions
Change made by setting top-level read-only permisisons, and any
other necessary permissions set as job-level.

Closes #1421

Signed-off-by: Diogo Teles Sant'Anna <diogoteles@google.com>
2023-03-06 21:18:59 +01:00
Liao Tonglang
6bfa580559
http: Reduce times of checking if response has body (#1395)
Use a variable 'need_body' to store the result of
evhttp_response_needs_body(), then use the variable instead of call the function again.
2023-03-05 16:59:21 +01:00
Michael Ford
185e2f009b
build: improve mbedtls searching on macOS with brew for cmake (#1419)
This just copies the same logic used to find OpenSSL on macOS using homebrew, for finding mbedtls via brew. Without it, the build will fail out the box with a brew installed mbedtls.
2023-03-05 16:58:22 +01:00
Kurt Roeckx
4e6375e84c
Always have evutil_secure_rng_add_bytes available (#1427)
When libevent doesn't provide random the arc4 function, but they come from libc, there is no need to call this function, so make it do nothing.

Fixes: #1393
2023-03-05 16:56:56 +01:00
Zhipeng Xue
3a0cf34ba5 ws-chat-server: fix potential resource leak 2023-03-05 16:48:27 +01:00
Zhipeng Xue
bac9d10a6d
Fix potential null dereference in http-server (#1430)
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2023-03-04 22:13:54 +01:00
Zhipeng Xue
fa05966d74
test: fix potential null dereference in https_bind_ssl_bevcb (#1428)
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2023-03-04 22:12:04 +01:00
Cœur
557990cad3 Optimize arc4random_uniform() (by syncing with OpenBSD implementation)
1. In d4de062, in Feb 2010, libevent adopted OpenBSD implementation of
   arc4random_uniform.
2. In
   728918cba9,
   in Jun 2012, OpenBSD improved their implementation to be faster, by
   changing arc4random_uniform() to calculate ``2**32 % upper_bound'' as
   ``-upper_bound % upper_bound''.

Alternatively we can simply remove arc4random_uniform() since it is not
used by libevent anyway, but let's just sync the header for now.
2023-03-02 07:51:14 +01:00
Cœur
e96e98aea5 evdns: fix "Branch condition evaluates to a garbage value" in reply_parse 2023-03-02 07:41:08 +01:00
Cœur
3bcc92cf59 Fix the value is never actually read from 'argument' in evhttp_parse_query_impl()
Although the value stored to 'argument' is used in the enclosing
expression, the value is never actually read from 'argument'
2023-03-02 07:32:17 +01:00
Cœur
b84fee24ab Fix "Value stored to 'a' is never read" in SHA1Transform()
Using same fix as used in android [1].

  [1]: android.googlesource.com/platform/dalvik/+/android-4.4.2_r2/libdex/sha1.cpp#193
2023-03-02 07:29:18 +01:00
Azat Khuzhin
bcefdbc67a
Merge pull request #1418 from fanquake/use_fortify_source_3
build: use FORTIFY_SOURCE=3 in hardening option
2023-02-14 09:56:03 +01:00
fanquake
e89ddd405b
build: use FORTIFY_SOURCE=3 in autotools build 2023-02-13 16:06:29 +00:00
fanquake
38cd76f09c
build: use FORTIFY_SOURCE=3 in CMake build 2023-02-13 16:05:58 +00:00