4720 Commits

Author SHA1 Message Date
Azat Khuzhin
9e346936d4 Ignore unknown pragmas
Since new compilers has new checks (like -Wdangling-pointer), and so to
avoid extra checks in cmake/autotools, simply suppress if the pragma is
unknown.
2022-11-12 19:00:10 +01:00
Azat Khuzhin
72a4fe76fc ws-chat-server: fix session name initialization (using of uninitialized data) 2022-11-12 19:00:10 +01:00
Azat Khuzhin
c8c730c8dc cmake: tiny cleanup 2022-11-12 18:56:03 +01:00
Azat Khuzhin
56d380b9b6 ws: ignore case while comparing values of Upgrade/Connection headers
Cc: @widgetii
Fixes: #1373
2022-11-12 18:46:43 +01:00
Azat Khuzhin
8482e227a8 ws-chat-server: avoid SIGSEGV in case of evws_new_session() failure 2022-11-12 18:44:44 +01:00
Azat Khuzhin
dda05f45e7 sample/ws-chat.html: allow to open it via file:// protocol 2022-11-12 18:11:08 +01:00
Azat Khuzhin
2dfad6c339 Suppress -Wdangling-pointer in event_signal_closure()
gcc 12 complains:

    [34/46] Building C object CMakeFiles/event_static.dir/event.c.o
    /src/le/libevent/event.c: In function ‘event_signal_closure’:
    /src/le/libevent/event.c:1384:32: warning: storing the address of local variable ‘ncalls’ in ‘*ev.ev_.ev_signal.ev_pncalls’ [-Wdangling-pointer=]
     1384 |                 ev->ev_pncalls = &ncalls;
          |                 ~~~~~~~~~~~~~~~^~~~~~~~~
    /src/le/libevent/event.c:1378:15: note: ‘ncalls’ declared here
     1378 |         short ncalls;
          |               ^~~~~~
    /src/le/libevent/event.c:1378:15: note: ‘ev’ declared here
2022-11-12 18:06:09 +01:00
Azat Khuzhin
e1d7d3e40a sha1: ignore -Wstringop-overread warning
Fixes the following:

    [4/38] Building C object CMakeFiles/event_shared.dir/sha1.c.o
    In function ‘SHA1Update’,
        inlined from ‘SHA1Final’ at /src/le/libevent/sha1.c:274:5,
        inlined from ‘builtin_SHA1’ at /src/le/libevent/sha1.c:292:5:
    /src/le/libevent/sha1.c:228:13: warning: ‘SHA1Transform’ reading 64 bytes from a region of size 7 [-Wstringop-overread]
      228 |             SHA1Transform(context->state, *(const unsigned char (*)[64])&data[i]);
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /src/le/libevent/sha1.c:228:13: note: referencing argument 2 of type ‘const unsigned char[64]’
    /src/le/libevent/sha1.c: In function ‘builtin_SHA1’:
    /src/le/libevent/sha1.c:80:13: note: in a call to function ‘SHA1Transform’
       80 | static void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
          |             ^~~~~~~~~~~~~
2022-11-12 17:56:51 +01:00
Azat Khuzhin
23a01aa227 sha1: hide SHA1_CTX 2022-11-12 16:42:10 +01:00
OgreTransporter
ef8f8caab6
Fix syntax error (#1369) 2022-11-04 23:52:01 +01:00
Michael Madsen
ff99f67a1a
fixed missing check for null after strdup in evutil_inet_pton_scope (#1366) 2022-11-04 11:59:17 +03:00
Leon George
3ec3b469b8
ws: fix compile error on centos 7 - very old compiler (#1359)
* http: fix typo

* ws: fix comile error

On CentOS:

  CC       ws.lo
ws.c: In function 'get_ws_frame':
ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode
   for (int i = 0; i < payload_len; i++) {
   ^
ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code
2022-10-23 14:47:23 +03:00
Azat Khuzhin
f04a70f0fc Fix data-race in ws code (#1360)
@widgetii:

  "
  =================================================================
  ==985==ERROR: AddressSanitizer: heap-use-after-free on address 0xb24323e5 at pc 0xb6a06f1c bp 0x9fffc694 sp 0x9fffc260
  WRITE of size 2 at 0xb24323e5 thread T22
      #0 0xb6a06f1b in __interceptor_memcpy.part.43 (/usr/lib/libasan.so.5+0x41f1b)

  0xb24323e5 is located 229 bytes inside of 512-byte region [0xb2432300,0xb2432500)
  freed by thread T0 (app) here:
      #0 0xb6a849df in free (/usr/lib/libasan.so.5+0xbf9df)
      #1 0xb64b6e07 in evbuffer_drain (/usr/lib/libevent_core-2.2.so.1+0x9e07)

  previously allocated by thread T22 here:
      #0 0xb6a84d17 in __interceptor_malloc (/usr/lib/libasan.so.5+0xbfd17)
      #1 0xb64b3d1b  (/usr/lib/libevent_core-2.2.so.1+0x6d1b)
      #2 0x61223 in onIceCandidateHandler /home/dima/git/app/src/webrtc/local.c:116
      #3 0x19296f in onNewIceLocalCandidate /home/dima/git/webrtc-c/src/source/PeerConnection/PeerConnection.c:471
  "

* upstream/pr/1360:
  Remove bad copy-paste
  Add locks for server WS, fixes #1357
2022-10-22 22:24:40 +02:00
Dmitry Ilyin
e8f5a61d6d Remove bad copy-paste 2022-10-12 22:15:21 +03:00
Dmitry Ilyin
c2ecb4acb5 Add locks for server WS, fixes #1357 2022-10-12 14:13:44 +03:00
Ryan Pavlik
8f47d8de28 cmake: Fix Android build.
Android/Bionic C library needs no special flags to have threading support.
Found when trying to build with vcpkg.
2022-10-08 19:27:21 +03:00
Azat Khuzhin
285fc7cc6d
Use heap-bases contexts for MbedTLS handles (#1355)
@widgetii:

"Recently after studying [https-client.c code](https://github.com/libevent/libevent/blob/master/sample/https-client.c#L532) I found that I cannot use MbedTLS with `bufferevent_mbedtls_socket_new` same way as for OpenSSL in other than hello-world code. In mentioned sample code, ssl context is created by `SSL_new()` (as heap-based pointer), but for MbedTLS stack value is used. The issue is in different semantics because OpenSSL is responsible for memory allocation and release for its context, but for MbedTLS it turns out user should do the same manually.

I expect that in both cases, setting option `BEV_OPT_CLOSE_ON_FREE` will free all linked resources, but in case of MbedTLS I have memory leak after connection is closed.

My proposal is:
1. Provide new `mbedtls_ssl_new` helper-function for end-user that do the same job as `SSL_new()` and use it and example in sample:

```c
mbedtls_ssl_context *mbedtls_ssl_new(const mbedtls_ssl_config *conf) {
  mbedtls_ssl_context *ssl = calloc(1, sizeof(*ssl));
  mbedtls_ssl_init(ssl);
  mbedtls_ssl_setup(ssl, conf);
  return ssl;
}
```

2. Add `free(ctx->ssl)` right after https://github.com/libevent/libevent/blob/master/bufferevent_mbedtls.c#L68"

Fixes: #1354
2022-10-08 19:26:24 +03:00
Dmitry Ilyin
aa163a4f29 Fix memleak in regress tests 2022-10-04 21:42:30 +03:00
Dmitry Ilyin
10ed1f1c28 Change code for samples 2022-10-04 17:57:01 +03:00
Dmitry Ilyin
88317a4ef8 Add helpers and all regress tests are passed 2022-10-04 17:49:22 +03:00
jackerli(李剑)
b5b4c7fed5 fix: arc4_getword integer overflow, detected by -fsanitize=undefined 2022-10-03 23:41:33 +03:00
Dmitry Antipov
117ee9a03f epoll: use epoll_pwait2() if available
On GNU/Linux with epoll backend, prefer epoll_pwait2() if available,
which is useful to support the timeout with microsecond precision.
2022-09-27 22:07:43 +03:00
zhenhaonong
f8bb9d8484 Fix socketpair failure when temporary directory has non-latin character 2022-09-26 21:43:21 +03:00
Dmitry Ilyin
211c6653ae Add manual CMAKE_C_BYTE_ORDER set for old CMake 2022-09-26 21:42:02 +03:00
Azat Khuzhin
ceb6bcd68a ci: disable freebsd 13.0 builds (due to issues in the image)
Before it fails with:

   exec ssh: pkg install -y  mbedtls cmake python3
    /bin/bash /Users/runner/work/_actions/vmactions/freebsd-vm/v0/run.sh execSSH
    Config file: freebsd-13.0.conf
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    Warning: no access to tty (Bad file descriptor).
    Thus no job control in this shell.
    Installing pkg-1.18.3...
    Newer FreeBSD version for package pkg:
    To ignore this error set IGNORE_OSVERSION=yes
    - package: 1301000
    - running kernel: 1300139
    Ignore the mismatch and continue? [y/N]:
    Failed to install the following 1 package(s): /tmp//pkg.txz.18yvwm
    Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/quarterly, please wait...
    Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
    Error: The process '/bin/bash' failed with exit code 1

And now with:
  ld-elf.so.1: /lib/libc.so.7: version FBSD_1.7 required by /usr/local/lib/libpython3.9.so.1.0 not found

Commenting for now, anyway we do not need such huge CI matrix, because
we have only public workers, and they are pretty busy.

Cc: @Neilpang
2022-09-14 22:14:28 +02:00
Azat Khuzhin
9174ba9242 .github/workflows/build.yml: Cleanup trailing whitespaces 2022-09-14 22:13:12 +02:00
Dmitry Ilyin
53f9c42095 Fix conflict with SHA1 function from openssl 2022-09-14 23:10:55 +03:00
Dmitry Ilyin
e8313084f9
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.

Implementation was inspired by modified Libevent source code in ipush project
[1].

  [1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable

Also, WebSocket-based chat server was added as a sample.
2022-09-12 22:16:56 +03:00
Keelan Cannoo
bb41229ff4
Make rekey interval less predictable (#1331) 2022-09-12 22:12:47 +03:00
Azat Khuzhin
039e8d96a4 Add openssl-compat.h into HDR_PRIVATE
Fixes: #1334
2022-09-11 22:08:32 +02:00
mareksm
b19af675c7
Fix non-std printf %p arguments (#1327)
* Fix non-std printf %p arguments when running with -Werror -pedantic-errors

Co-authored-by: Mareks Malnacs <mareks.malnacs>
2022-08-28 15:27:04 +03:00
Azat Khuzhin
bb57cea387 test: fix util/getaddrinfo for netbsd (v2)
Fixes: c198b0ce ("test: fix util/getaddrinfo for netbsd")
Fixes: #1316
2022-08-14 09:56:50 +02:00
Azat Khuzhin
77a9b60e47
Merge pull request #1315 from yogo1212/http_per_socket_bebcb
In it's current form, libevent requires multiple struct evhttp objects to be created in order to enable listening on sockets with more than one type of encryption.

This change allows specifying per-socket how the associated bufferevents should be created.
Thus, it becomes possible to have multiple listening sockets with different encryption parameters using only one evttp.
2022-08-14 00:46:48 +02:00
Azat Khuzhin
c198b0ceb3 test: fix util/getaddrinfo for netbsd
Fixes: #1316
2022-08-13 20:48:49 +02:00
Borys Smejda
86b5d2e951 Fixed CMake configuration failure (libevent#1321)
Deleted usage of CMake feature 'file(REAL_PATH'
which is available from version 3.19
with an old 'get_filename_component' so that
older version of CMake can still be used
to configure the project.
2022-08-13 20:15:06 +02:00
Leon M. George
1bdc91350e http: allow setting bevcb per socket
Co-authored-by: Azat Khuzhin <azat@libevent.org>
v2: remove handling of HTTP_BIND_IPV6
2022-08-13 20:12:18 +02:00
Azat Khuzhin
a4cdc3c5e8 test: allow to run init_ssl() multiple times 2022-08-13 20:12:18 +02:00
Azat Khuzhin
4ca417afa4 test: add a comment for init_ssl() about suppressions for LSan 2022-08-13 20:12:08 +02:00
Dmitry Ilyin
99fd68abde Add check of mmap64 function and use it when available rather that mmap
There can be issues on 32-bit architectures to mmap 2+GiB file, and to
make this portable between different version of glibc, mmap64 was
prefered over _FILE_OFFSET_BITS
2022-08-09 00:18:10 +02:00
neil
b2aca3bc31 fix freebsd checks 2022-08-09 00:14:43 +02:00
neil
c08ee39969 fix freebsd checks 2022-08-09 00:14:43 +02:00
neil
4f662d662e Add freebsd CI checks
ci/linux skip
ci/macos skip
ci/windows skip
ci/mingw skip
2022-08-09 00:14:43 +02:00
Haowei Hsu
80c1e0b745 Search library name of Debug for find_event_lib. 2022-08-07 11:14:40 +02:00
Haowei Hsu
dd610b7781 Add postfix for Debug configuration. 2022-08-07 11:14:40 +02:00
Dmitry Ilyin
05a03d4a15 Add more HTTP_ response codes 2022-08-07 11:13:48 +02:00
Azat Khuzhin
3e7a73809e ci: increase number of attempts to 5 2022-07-12 21:57:41 +03:00
Azat Khuzhin
bfa526cefa ci: add retries
Right now it is possible for some tests to fail, because of lack of CPU
time.
And it is better to have green CI even if this will take longer.
2022-07-12 21:08:00 +03:00
Azat Khuzhin
d32649493a ci: use ubuntu 22.04 with clang 11 for sanitizers build (#1306)
* ci-tsan-recent:
  test: fix unused variable in rand test (catched by newer clang)
  ci: use ubuntu 22.04 with clang 11 for sanitizers build
2022-07-12 10:07:20 +03:00
Azat Khuzhin
33fb0e358a test: fix unused variable in rand test (catched by newer clang) 2022-07-12 09:54:36 +03:00
Azat Khuzhin
87c016a09e ci: use ubuntu 22.04 with clang 11 for sanitizers build
There are periodically some heap-use-after-free reported in ratelim
tests by TSan, which I cannot reproduce locally and even on CI it is
flaky.

Let's try to use recent clang, maybe it fixes some issues in sanitizers.

Refs: #1206
2022-07-12 08:08:25 +03:00