Commit 537a8027 authored by Arthur O'Dwyer's avatar Arthur O'Dwyer

Add a missing null-check, turning a segfault into an assertion.

Static analysis says:
src\tcp_address.cpp(297): error V595: The 'res' pointer was utilized before it was verified against nullptr. Check lines: 297, 301.
src\tcp_address.cpp(603): error V106: Implicit type conversion third argument 'full_bytes' of function 'memcmp' to memsize type.
src\tcp_address.cpp(603): error V526: The 'memcmp' function returns 0 if corresponding buffers are equal. Consider examining the condition for mistakes.

In fact the use of "memcmp" is correct, but the enclosing "if" isn't
necessary, and the compiler is happier if "full_bytes" is a size_t.
parent 6347d392
......@@ -294,12 +294,12 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_,
}
// Use the first result.
zmq_assert (res != NULL);
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address));
memcpy (&address, res->ai_addr, res->ai_addrlen);
// Cleanup getaddrinfo after copying the possibly referenced result.
if (res)
freeaddrinfo (res);
freeaddrinfo (res);
return 0;
}
......@@ -598,11 +598,9 @@ const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, co
}
if (address_mask < mask) mask = address_mask;
int full_bytes = mask / 8;
if (full_bytes) {
if (memcmp(our_bytes, their_bytes, full_bytes))
return false;
}
size_t full_bytes = mask / 8;
if (memcmp(our_bytes, their_bytes, full_bytes))
return false;
uint8_t last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU;
if (last_byte_bits) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment