Commit Graph

3172 Commits

Author SHA1 Message Date
Stephan Lachnit
05c2025412 poller.hpp: fix incorrect ZMQ_IOTHREAD_POLLER_* usage
Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
2023-11-01 00:53:40 +00:00
Yueshan
95caddb9a1 Update msg.cpp
allow the max_vsm_size of data can init as vsm type msg

the init message of vsm size should be <= max_vsm_size include equal size.
2023-10-22 11:47:21 +01:00
George Cockshull
058ad60b9a zmq_proxy_steerable: support non-REP socket types
Problem: reimplemented zmq_proxy_steerable control socket type is not
backwards compatible - replies are always sent.

In the past, zmq_proxy_steerable never sent a reply for
commands that weren't STATISTICS, so only really worked with PAIR and didn't
work at all with REP. Now it only supports REP and PAIR semantics changed. This
breaks compatibility with PAIR in a subtle and slightly annoying way if
HWMs are hit without reading the replies.

Solution: Add a check to send the empty reply only for
REP control sockets. This restores backwards compatibility, and supports
REP, PAIR, and SUB (for non-reply commands).

I had no knowledge of the pre-MPL-2.0 implementation. This fix is based
on docs and prior API usage. I contribute this under MPL-2.0.
2023-10-12 15:22:44 -04:00
George Cockshull
f8b3cc8108 Fix zmq_proxy_steerable PAUSE/RESUME
Problem: the new reimplementation of zmq_proxy_steerable had PAUSE/RESUME
that didn't follow expected behaviour. Possibly mixed up. Test didn't properly
cover the issue.

Solution: improve test coverage, fix the proxy command parsing.

I had no knowledge of the pre-MPL-2.0 implementation. This fix is based
on documented semantics and prior API usage. I contribute this
under MPL-2.0.
2023-10-12 15:22:44 -04:00
James Harvey
9d31965548
Handle tcp self connection issues (#4599) 2023-10-10 14:46:48 +01:00
Brett Viren
5712ad5138 A clean-room implementation of zmq_proxy_steerable().
It is contriubted under the MPL-2.0.

I had no knowledge of the previous implementation of zmq_proxy_steerable().

This version was developed based on expectations set in the old man page with one exception.  This version uses a REP/REQ for the proxy control protocol sockets.  The old man page example used PUB/SUB which is nonsensical given the STATISTICS command requires two way communication.
2023-10-08 19:56:03 -04:00
Nehal Patel
8cdc4ed71a
Problem: unused variables warnings
Solution: fix them
2023-10-04 09:51:43 +01:00
Jeffery Weston
ec013f3a17 fix assert error on late-joining subscriber after publisher has filled NORM buffer 2023-07-21 19:46:44 +01:00
Cornelius
ecc63d0d3b
Problem: long flag isn't set for subscriptions if topic has between 246 and 255 characters (#4564)
* Problem: long flag isn't set for subscriptions if topic has between 246 and 255 characters

Solution: fix V3.1 encoder to calculate long flag after evaluating the subscribe and cancel commands
2023-06-20 15:17:26 +01:00
Guillaume DELACOURT
5657b4586f Always allow DNS when resolving TCP and UDP adresses. DNS resolution is done after interface resolution, so it can always be enabled to have a fallback mecanism on hostname resolution. 2023-06-12 20:28:32 +01:00
Guillaume DELACOURT
797c7f09f8 When setting thread priority, always set the value to zero when the policy is not compatible. Also, only call nice when the priority is set to a strictly positive value. 2023-06-12 00:11:21 +01:00
Luca Boccassi
346907065f Problem: trailing whitespace
Solution: remove it
2023-06-06 18:00:08 +01:00
Stéphane Valès
de1bd5c8e7 Problem: relicensing forced to remove support for ZMQ_RECONNECT_IVL_MAX option
Solution: reimplement support for ZMQ_RECONNECT_IVL_MAX without knowledge of the previous code.
2023-06-06 15:15:22 +02:00
Luca Boccassi
da31917f4f Relicense from LGPL3 + exceptions to Mozilla Public License version 2.0
Relicense permission collected from all relevant authors as tallied at:
https://github.com/rlenferink/libzmq-relicense/blob/master/checklist.md
The relicense grants are collected under RELICENSE/ and will be moved
to the above repository in a later commit.

Fixes https://github.com/zeromq/libzmq/issues/2376
2023-06-05 20:31:47 +01:00
Luca Boccassi
7bbd49726b Problem: no permission to relicense ZMQ_RECONNECT_IVL_MAX
Solution: remove the implementation. Thijs Terlouw <thijsterlouw@gmail.com>,
the author, did not respond to requests to allow relicensing to MPL2,
so we have to remove his copyrighted work.
Remove the implementation and make get/set return -EOPNOTSUPP.
2023-06-05 00:22:20 +01:00
Luca Boccassi
ff47aeb791 Problem: no permission to relicense tweetnacl integration
Solution: remove implementation. Frank Hartmann <soundart@gmx.net>,
the author, rejected our request to relicense under MPL2, so we
have to remove his copyrighted work.
Tweetnacl is not security-supported and could not be used in
production environments anyway, the supported backend is libsodium.
2023-06-04 23:54:31 +01:00
Luca Boccassi
13bc1de421 Problem: no permission to relicense zmq_proxy_steerable
Solution: remove implementation. Laurent Alebarde <l.alebarde@free.fr>,
the author, did not respond to requests to allow relicensing to MPL2,
so we have to remove his copyrighted work.
Make the API into an empty stub that returns -EOPNOTSUPP.
2023-06-04 23:54:31 +01:00
Jeff Weston
eaaea73bf1
Change NORM to set TTL using MULTICAST_HOPS sockopt (#4552)
* Change NORM to set TTL using MULTICAST_HOPS instead of hard-coding.  Changes default TTL from 255 to 1.
2023-05-19 20:53:20 +01:00
Jeff Weston
2d30020691
Add NORM Transport configuration sockopts (#4541)
* added NORM transport configuration socket options, and enabled NORM use of existing sockopts ZMQ_RATE for NORM fixed-rate operation, and ZMQ_TOS
2023-04-20 18:55:40 +01:00
Luca Boccassi
8c725093ac
Merge pull request #4509 from sphaero/udploop
Problem: infinite loop binding a dgram socket if it fails
2023-02-06 15:23:35 +00:00
Arnaud Loonstra
b261f9a678 treat bind errors as a protocol_error instead of connection_error preventing an infinite loop of trying to create the udp socket as through the protocol_error the creation of the socket fails 2023-02-03 16:33:18 +01:00
Luca Boccassi
6e2d632b18
Merge pull request #4502 from casaroli/fix-for-nuttx
Fixes for memory allocation and zero size
2023-02-03 09:16:26 +00:00
Marco Casaroli
d16db180d3 Do not break if malloc size is zero
I get a scenario where `size_` is `0` so there is nothing to `malloc()`.

According to `malloc(3)`:

If size is 0, then malloc() returns either NULL, or a unique pointer value thatcan later be
success‐fully passed to free().

According to `free(3)`:

If ptr is NULL, no operation is performed.

So, if `size_` is null and `_data` also, there is no OOM error.

We can adjust the assert to not fail on this scenario.
2023-02-03 09:35:35 +01:00
Daira Hopwood
6dc559c072 #4494 added calls to snprintf, but did not take into account that snprintf
can truncate, and then return the number of characters that would have been
written without truncation.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-01 19:15:46 +00:00
Marco Casaroli
f049edbf12 Use parenthesis for alloc_assert macro 2023-01-31 14:46:46 +01:00
Arnaud Loonstra
f7df6c8599 deprecate sprint and replace with snprintf 2023-01-24 22:45:48 +01:00
Luca Boccassi
ee9c0919e2 Problem: address sanitizer complains about uninitialised func pointer
Solution: just call the function directly
2023-01-15 23:44:00 +00:00
Luca Boccassi
7781dd1bbd Problem: formatting errors with clang-format-11
Solution: apply update
2023-01-12 01:07:06 +00:00
Ilya Kondrashkin
04720b6b91 Problem: message can't be received due to signal
Issue caught in Golang runtime, which widely uses signal SIGURG for
scheduling. Sometimes messages cannot be received. Technically
socket_base_t::process_commands() returns failure even if some commands were
processed, but next message from mailbox could not be received during interrupt.

Solution: retry receiving from mailbox with zero timeout after EINTR.

Signed-off-by: Ilya Kondrashkin <ikondrashkin@nfware.com>
2023-01-10 16:04:56 +00:00
Sergei Trofimovich
438d5d8839 src/secure_allocator.hpp: define missing 'rebind' type
`gcc-13` added an assert to standard headers to make sure custom
allocators have intended implementation of rebind type instead
of inherited rebind. gcc change:
    https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=64c986b49558a7

Without the fix build fails on this week's `gcc-13` as:

    [ 92%] Building CXX object tests/CMakeFiles/test_security_curve.dir/test_security_curve.cpp.o
    In file included from /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/ext/alloc_traits.h:34,
                     from /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/stl_uninitialized.h:64,
                     from /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/memory:69,
                     from tests/../src/secure_allocator.hpp:42,
                     from tests/../src/curve_client_tools.hpp:49,
                     from tests/test_security_curve.cpp:53:
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/alloc_traits.h: In instantiation of 'struct std::__allocator_traits_base::__rebind<zmq::secure_allocator_t<unsigned char>, unsigned char, void>':
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/alloc_traits.h:94:11:   required by substitution of 'template<class _Alloc, class _Up> using std::__alloc_rebind = typename std::__allocator_traits_base::__rebind<_Alloc, _Up>::type [with _Alloc = zmq::secure_allocator_t<unsigned char>; _Up = unsigned char]'
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/alloc_traits.h:228:8:   required by substitution of 'template<class _Alloc> template<class _Tp> using std::allocator_traits< <template-parameter-1-1> >::rebind_alloc = std::__alloc_rebind<_Alloc, _Tp> [with _Tp = unsigned char; _Alloc = zmq::secure_allocator_t<unsigned char>]'
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/ext/alloc_traits.h:126:65:   required from 'struct __gnu_cxx::__alloc_traits<zmq::secure_allocator_t<unsigned char>, unsigned char>::rebind<unsigned char>'
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/stl_vector.h:88:21:   required from 'struct std::_Vector_base<unsigned char, zmq::secure_allocator_t<unsigned char> >'
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/stl_vector.h:423:11:   required from 'class std::vector<unsigned char, zmq::secure_allocator_t<unsigned char> >'
    tests/../src/curve_client_tools.hpp:64:76:   required from here
    /<<NIX>>/gcc-13.0.0/include/c++/13.0.0/bits/alloc_traits.h:70:31: error: static assertion failed: allocator_traits<A>::rebind_alloc<A::value_type> must be A
       70 |                         _Tp>::value,
          |                               ^~~~~

The change adds trivial `rebind` definition with expected return type
and satisfies conversion requirements.
2022-12-20 23:00:53 +00:00
Francesco Montorsi
c59104a01d
Add ZMQ_TOPICS_COUNT socket option (#4459) 2022-11-29 12:00:11 +00:00
Đorđije Manojlović
6cc694d8c2 Problem: Handshake timeout error with ZMTP_2_0
When two parties are trying to establish ZMTP connection and do a
handshake, in which one partie selects hanshake version 2 or lower
has been selected, handshake timer fires always (by default after 30s)
as the timer never gets cancelled.

Solution: Cancel handshake timer after handhake has been done.
2022-11-11 12:26:44 +01:00
Min RK
bf906ee346
AF_UNIX support may fail on bind 2022-09-08 15:10:04 +02:00
Min RK
b2921d7183
check rc in make_fdpair
since it can fail, e.g. Windows + AF_UNIX
2022-09-08 11:17:51 +02:00
Abael He
4e193f36fc Problem: some tools misdetect null access or broken libsodium implementation
Build all projects

** BUILD SUCCEEDED **

bash-3.2# cd  bin/Debug/
bash-3.2# for x in ./* ; do ./$x 1> /dev/null 2>/dev/null  || echo $x ; done
./test_bind_curve_fuzzer
./test_bind_fuzzer
./test_bind_null_fuzzer
./test_connect_curve_fuzzer
./test_connect_fuzzer
./test_connect_null_fuzzer
Segmentation fault: 11
./test_security_curve
./test_z85_decode_fuzzer
bash-3.2# ./test_bind_curve_fuzzer
bash-3.2# ./test_bind_curve_fuzzer
bash-3.2# ./test_bind_fuzzer
bash-3.2# ./test_bind_null_fuzzer
bash-3.2# ./test_connect_curve_fuzzer
bash-3.2# ./test_connect_fuzzer
bash-3.2# ./test_security_curve
Segmentation fault: 11
bash-3.2# lldb ./test_security_curve
(lldb) target create "./test_security_curve"
Current executable set to '/Users/abaelhe/Downloads/libzmq-master/build/bin/Debug/test_security_curve' (x86_64).
(lldb) r
Process 39009 launched: '/Users/abaelhe/Downloads/libzmq-master/build/bin/Debug/test_security_curve' (x86_64)
Process 39009 stopped
* thread #3, name = 'ZMQbg/IO/0', stop reason = signal SIGSEGV
    frame #0: 0x00007ff80f64f192 libsystem_kernel.dylib`__pthread_sigmask + 10
libsystem_kernel.dylib`__pthread_sigmask:
->  0x7ff80f64f192 <+10>: jae    0x7ff80f64f19c            ; <+20>
    0x7ff80f64f194 <+12>: movq   %rax, %rdi
    0x7ff80f64f197 <+15>: jmp    0x7ff80f64a1c5            ; cerror_nocancel
    0x7ff80f64f19c <+20>: retq
Target 0: (test_security_curve) stopped.
(lldb) bt
warning: could not find Objective-C class data in the process. This may reduce the quality of type information available.
* thread #3, name = 'ZMQbg/IO/0', stop reason = signal SIGSEGV
  * frame #0: 0x00007ff80f64f192 libsystem_kernel.dylib`__pthread_sigmask + 10
    frame #1: 0x00007ff80f685acb libsystem_pthread.dylib`pthread_sigmask + 9
    frame #2: 0x00007ff80f5d1d19 libsystem_c.dylib`abort + 112
    frame #3: 0x0000000100333551 libsodium.23.dylib`_out_of_bounds.cold.1 + 17
    frame #4: 0x0000000100316229 libsodium.23.dylib`_out_of_bounds + 9
    frame #5: 0x0000000100316218 libsodium.23.dylib`sodium_free + 408
    frame #6: 0x00000001005a6d0d libzmq.5.dylib`zmq::secure_allocator_t<unsigned char>::deallocate(this=0x00007000014c6ce0, p="", (null)=96) at secure_allocator.hpp:63:56
    frame #7: 0x00000001005a6c25 libzmq.5.dylib`std::__1::allocator_traits<zmq::secure_allocator_t<unsigned char> >::deallocate(__a=0x00007000014c6ce0, __p="", __n=96) at allocator_traits.h:282:13
    frame #8: 0x00000001005a6484 libzmq.5.dylib`std::__1::__vector_base<unsigned char, zmq::secure_allocator_t<unsigned char> >::~__vector_base(this=0x00007000014c6cd0) at vector:488:9
    frame #9: 0x00000001005acae2 libzmq.5.dylib`std::__1::vector<unsigned char, zmq::secure_allocator_t<unsigned char> >::~vector(this=0x00007000014c6cd0 size=0) at vector:579:5
    frame #10: 0x00000001005ac165 libzmq.5.dylib`std::__1::vector<unsigned char, zmq::secure_allocator_t<unsigned char> >::~vector(this=0x00007000014c6cd0 size=0) at vector:574:5
    frame #11: 0x00000001005ab2e7 libzmq.5.dylib`zmq::curve_server_t::process_hello(this=0x000000010182c600, msg_=0x00006000037001e8) at curve_server.cpp:208:1
    frame #12: 0x00000001005aad30 libzmq.5.dylib`zmq::curve_server_t::process_handshake_command(this=0x000000010182c600, msg_=0x00006000037001e8) at curve_server.cpp:104:18
    frame #13: 0x000000010062ccd7 libzmq.5.dylib`zmq::stream_engine_base_t::process_handshake_command(this=0x000000010182d400, msg_=0x00006000037001e8) at stream_engine_base.cpp:491:32
    frame #14: 0x000000010062ba21 libzmq.5.dylib`zmq::stream_engine_base_t::in_event_internal(this=0x000000010182d400) at stream_engine_base.cpp:309:14
    frame #15: 0x000000010062b665 libzmq.5.dylib`zmq::stream_engine_base_t::in_event(this=0x000000010182d400) at stream_engine_base.cpp:243:22
    frame #16: 0x00000001005c0889 libzmq.5.dylib`zmq::kqueue_t::loop(this=0x00006000037000c0) at kqueue.cpp:218:30
    frame #17: 0x00000001005eefa9 libzmq.5.dylib`zmq::worker_poller_base_t::worker_routine(arg_=0x00006000037000c0) at poller_base.cpp:146:51
    frame #18: 0x0000000100637e66 libzmq.5.dylib`thread_routine(arg_=0x0000600003700100) at thread.cpp:256:5
    frame #19: 0x00007ff80f6864e1 libsystem_pthread.dylib`_pthread_start + 125
    frame #20: 0x00007ff80f681f6b libsystem_pthread.dylib`thread_start + 15
(lldb)
2022-08-10 22:21:00 +01:00
Abama cai
717d1980ee Problem: get_opt function read the options value maybe not thread safe
Solution: use scoped lock to prevent them from being modified during reading
2022-08-10 22:35:14 +08:00
Dimitris Apostolou
6b8dd84a63
Fix typos 2022-02-11 00:45:06 +02:00
Jasper Bekkers
aea0665eec
Fix minor casing issue in include files
This fails when compiling x86_64-pc-windows-msvc targets on a case sensitive file system.
2022-02-06 22:12:19 +01:00
fanquake
6473bf4166 problem: kevent udata is now void* on NetBSD Current (10)
solution: check for the intptr_t variant in configure.
2022-01-03 18:03:14 +00:00
Tarmo Tänav
74529d97b2 Problem: ROUTER loses first frame metadata on message prefetch
Solution: copy metadata on prefetch to the first frame
2021-12-16 10:17:44 +02:00
patrick-volante
2c415b6f68 Problem: inside the event array, epoll return an event with invalid data pointer which create a segmentation fault
Tests to prevent segmentation fault due to null pointer are added.
2021-12-03 11:58:20 +01:00
myd7349
471ea68caf Problem: struct sockaddr_un redefinition
The definition of sockaddr_un should be protected by the include guard.
2021-11-25 08:35:58 +08:00
myd7349
5eb0b00c87
Problem: In rare cases, afunix.h doesn't contain a definition for struct sockaddr_un (#4310)
* Problem: In rare cases, afunix.h doesn't contain a definition for struct sockaddr_un

According to https://github.com/microsoft/vcpkg/issues/21623,
struct sockaddr_un might be unavailable on some machines even afunix.h exists.

For example, on some machines, the content of afunix.h looks like this:
typedef struct _SOCKADDR_UN
{
     ADDRESS_FAMILY Family;
     wchar_t Path[63];
} SOCKADDR_UN, *PSOCKADDR_UN;

but on other machines, it may looks like this:
#define UNIX_PATH_MAX 108

typedef struct sockaddr_un
{
    ADDRESS_FAMILY sun_family;
    char sun_path[UNIX_PATH_MAX];
} SOCKADDR_UN, *PSOCKADDR_UN;

Fixes #3949

References:
- [Enable Unix-domain sockets support on Windows](8f3ec75de4)
- [AF_UNIX equivalent for Windows](https://stackoverflow.com/questions/9029174/af-unix-equivalent-for-windows)
- https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
2021-11-24 14:55:45 +00:00
Niyas Sait
0d86aa517f Fix linting error reported by clang-format 2021-11-15 10:31:21 +00:00
Niyas Sait
e9f86fee61 Get cycle count from ARM64 PMCCNTR_EL0 register 2021-11-15 09:12:11 +00:00
Paul Thiele
6737d50933 Problem: if ZMQ_XPUB_VERBOSER is used with proxies unsubscribe messages are lost
Solution: add socket option ZMQ_XSUB_VERBOSE_UNSUBSCRIBE to forward all unsubscribe messages
2021-11-05 15:12:31 +01:00
Luca Boccassi
d62fd1ac7a Problem: formatting broken
Solution: run make clang-format-diff
2021-11-03 19:39:50 +00:00
Qqzk
bb7a1cc018 Update decoder_allocators.cpp
zmq::shared_message_memory_allocator::deallocate () need to descontruct the object created by new operator.
2021-11-03 19:37:41 +00:00
mjvankampen
36d6b5d923
Problem: polling_util.hpp missing sys/select.h include (#4283)
* Problem: polling_util.hpp missing sys/select.h include

Solution: include sys/select.h
2021-10-21 20:56:32 +01:00
E. G. Patrick Bos
36e4c9b474
add zmq_ppoll
zmq_ppoll mostly mimics zmq_poll behavior, except for the added feature of being able to specify a signal mask. Signals in this mask will be blocked during execution of zmq_ppoll. Switching of the process' active signal mask happens atomically with the actual poll call, so that no race conditions can occur. This behavior is useful when one wants to gracefully handle POSIX signals without race conditions. See e.g. the discussion below https://250bpm.com/blog:12/ for an explanation.

Also includes two new tests:
1. test_zmq_ppoll_fd does the same thing as test_zmq_poll_fd, demonstrating backwards compatibility with zmq_poll when used with a default signal mask.
2. test_zmq_ppoll_signals demonstrates the use of zmq_ppoll with a signal mask, blocking out SIGTERM everywhere except in zmq_ppoll, allowing to handle the signal in one place without having to worry about race conditions.
2021-09-24 11:04:20 +02:00