#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>
This commit is contained in:
Daira Hopwood 2023-02-01 15:15:19 +00:00
parent 333c88e9ff
commit 6dc559c072
3 changed files with 21 additions and 5 deletions

15
RELICENSE/daira.md Normal file
View File

@ -0,0 +1,15 @@
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL
This is a statement by Daira Hopwood
that grants permission to relicense hir copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current ZeroMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the Github handle "daira", with
commit author "Daira Hopwood <daira@jacaranda.org>", are copyright of Daira Hopwood.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Daira Hopwood
2023/02/01

View File

@ -129,8 +129,9 @@ static std::string make_address_string (const char *hbuf_,
pos += hbuf_len;
memcpy (pos, ipv6_suffix_, sizeof ipv6_suffix_ - 1);
pos += sizeof ipv6_suffix_ - 1;
pos += snprintf (pos, max_port_str_length + 1 * sizeof (char), "%d",
ntohs (port_));
int res = snprintf (pos, max_port_str_length + 1, "%d", ntohs (port_));
zmq_assert (res > 0 && res < (int) (max_port_str_length + 1));
pos += res;
return std::string (buf, pos - buf);
}

View File

@ -367,9 +367,9 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_,
const char *const name = inet_ntoa (addr_->sin_addr);
char port[6];
const int port_len = snprintf (port, 6 * sizeof (char), "%d",
static_cast<int> (ntohs (addr_->sin_port)));
zmq_assert (port_len > 0);
const int port_len =
snprintf (port, 6, "%d", static_cast<int> (ntohs (addr_->sin_port)));
zmq_assert (port_len > 0 && port_len < 6);
const size_t name_len = strlen (name);
const int size = static_cast<int> (name_len) + 1 /* colon */