[zeromq-dev] Compilation fails when NDEBUG is enabled.

Chernyshev Vyacheslav astellar at ro.ru
Fri Aug 24 00:29:51 CEST 2012

Yeah, and there are still issues with this test, checked it right now.
First, zmq_bind splits its argument into 2 parts: protocol and address 
("tcp" and "" in our case). 
zmq::tcp_listener_t::set_address function receives already stripped 
address part, so comparison will fail again. It seems that I still can 
prepare another pull request :) But this issue is not so important, as 
during digging through the pitfalls of this test I've found a much worse 
error in library itself. Let me explain it and at first provide a stack 
trace that I can refer to:

#1  zmq::ctx_t::monitor_event () at ctx.cpp:405
#2  zmq::socket_base_t::monitor_event () at socket_base.cpp:1004
#3  zmq::session_base_t::monitor_event () at session_base.cpp:293
#4  zmq::tcp_connecter_t::start_connecting () at tcp_connecter.cpp:165
#5  zmq::tcp_connecter_t::process_plug () at tcp_connecter.cpp:83

Here we see a so-called delayed connect. In tcp_connecter.cpp:165 we 
call a function with variable-length argument list, passing 2 
parameters. Everything is nice so far, let's go to session_base.cpp:293. 
And here a big boom happens. I see that programmer's effort was to 
forward variadic arguments of one function to variadic arguments of 
another function, but it can not be done the way that it was coded here. 
What this code does is passing va_list as a parameter to 
zmq::socket_base_t::monitor_event, where it forms another va_list, 
passes to zmq::ctx_t::monitor_event and tries to extract 2 arguments. It 
clearly fails and we receive absolutely undefined behaviour. As a result 
any monitor event triggered by zmq::session_base_t::monitor_event does 
not work at all.

As zmq::socket_base_t::monitor_event is used on its own, probably there 
have to be 2 versions of this function. One that has ellipsis and one 
that accepts valist, something like printf/vprintf family.

P.S. Chernyshev is my last name. I know that neither it, nor my first 
name are easy to type/pronounce for English-speaking people, so you can 
just type Slava (it is a short form of first name) when required to 
avoid copy-pasting :)

More information about the zeromq-dev mailing list