treewide: Invalid type in argument to printf format specifier, CWE-686

Harmless except for two bad debugging prints.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2022-04-04 23:35:32 +02:00
parent 54f8bf8246
commit dbd0a7035c
4 changed files with 32 additions and 32 deletions

View file

@ -53,12 +53,12 @@ void packet_add_do(struct pool *p, size_t len, const char *start,
} }
if (len > UINT16_MAX) { if (len > UINT16_MAX) {
trace("add packet length %lu, %s:%i", func, line); trace("add packet length %lu, %s:%i", len, func, line);
return; return;
} }
if ((unsigned int)((intptr_t)start - (intptr_t)p->buf) > UINT32_MAX) { if ((unsigned int)((intptr_t)start - (intptr_t)p->buf) > UINT32_MAX) {
trace("add packet start %p, buffer start %lu, %s:%i", trace("add packet start %p, buffer start %p, %s:%i",
start, p->buf, func, line); start, p->buf, func, line);
return; return;
} }
@ -111,7 +111,7 @@ void *packet_get_do(const struct pool *p, size_t index, size_t offset,
if (len + offset > p->pkt[index].len) { if (len + offset > p->pkt[index].len) {
if (func) { if (func) {
trace("data length %lu, offset %lu from length %lu, " trace("data length %lu, offset %lu from length %u, "
"%s:%i", len, offset, p->pkt[index].len, "%s:%i", len, offset, p->pkt[index].len,
func, line); func, line);
} }

6
pcap.c
View file

@ -88,7 +88,7 @@ void pcap(const char *pkt, size_t len)
h.caplen = h.len = len; h.caplen = h.len = len;
if (write(pcap_fd, &h, sizeof(h)) < 0 || write(pcap_fd, pkt, len) < 0) if (write(pcap_fd, &h, sizeof(h)) < 0 || write(pcap_fd, pkt, len) < 0)
debug("Cannot log packet, length %u", len); debug("Cannot log packet, length %lu", len);
} }
/** /**
@ -123,7 +123,7 @@ void pcapm(const struct msghdr *mh)
return; return;
fail: fail:
debug("Cannot log packet, length %u", iov->iov_len - 4); debug("Cannot log packet, length %lu", iov->iov_len - 4);
} }
/** /**
@ -161,7 +161,7 @@ void pcapmm(const struct mmsghdr *mmh, unsigned int vlen)
} }
return; return;
fail: fail:
debug("Cannot log packet, length %u", iov->iov_len - 4); debug("Cannot log packet, length %lu", iov->iov_len - 4);
} }
/** /**

38
tcp.c
View file

@ -848,7 +848,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_conn *conn)
it.it_value.tv_sec = ACT_TIMEOUT; it.it_value.tv_sec = ACT_TIMEOUT;
} }
debug("TCP: index %i, timer expires in %u.%03us", conn - tc, debug("TCP: index %li, timer expires in %lu.%03lus", conn - tc,
it.it_value.tv_sec, it.it_value.tv_nsec / 1000 / 1000); it.it_value.tv_sec, it.it_value.tv_nsec / 1000 / 1000);
timerfd_settime(conn->timer, 0, &it, NULL); timerfd_settime(conn->timer, 0, &it, NULL);
@ -868,14 +868,14 @@ static void conn_flag_do(const struct ctx *c, struct tcp_conn *conn,
return; return;
conn->flags &= flag; conn->flags &= flag;
debug("TCP: index %i: %s dropped", (conn) - tc, debug("TCP: index %li: %s dropped", conn - tc,
tcp_flag_str[fls(~flag)]); tcp_flag_str[fls(~flag)]);
} else { } else {
if (conn->flags & flag) if (conn->flags & flag)
return; return;
conn->flags |= flag; conn->flags |= flag;
debug("TCP: index %i: %s", (conn) - tc, debug("TCP: index %li: %s", conn - tc,
tcp_flag_str[fls(flag)]); tcp_flag_str[fls(flag)]);
} }
@ -924,12 +924,12 @@ static void conn_event_do(const struct ctx *c, struct tcp_conn *conn,
new += 5; new += 5;
if (prev != new) { if (prev != new) {
debug("TCP: index %i, %s: %s -> %s", (conn) - tc, debug("TCP: index %li, %s: %s -> %s", conn - tc,
num == -1 ? "CLOSED" : tcp_event_str[num], num == -1 ? "CLOSED" : tcp_event_str[num],
prev == -1 ? "CLOSED" : tcp_state_str[prev], prev == -1 ? "CLOSED" : tcp_state_str[prev],
(new == -1 || num == -1) ? "CLOSED" : tcp_state_str[new]); (new == -1 || num == -1) ? "CLOSED" : tcp_state_str[new]);
} else { } else {
debug("TCP: index %i, %s", (conn) - tc, debug("TCP: index %li, %s", conn - tc,
num == -1 ? "CLOSED" : tcp_event_str[num]); num == -1 ? "CLOSED" : tcp_event_str[num]);
} }
@ -1371,8 +1371,8 @@ static void tcp_hash_insert(const struct ctx *c, struct tcp_conn *conn,
tc_hash[b] = conn; tc_hash[b] = conn;
conn->hash_bucket = b; conn->hash_bucket = b;
debug("TCP: hash table insert: index %i, sock %i, bucket: %i, next: %p", debug("TCP: hash table insert: index %li, sock %i, bucket: %i, next: "
conn - tc, conn->sock, b, CONN_OR_NULL(conn->next_index)); "%p", conn - tc, conn->sock, b, CONN_OR_NULL(conn->next_index));
} }
/** /**
@ -1395,7 +1395,7 @@ static void tcp_hash_remove(const struct tcp_conn *conn)
} }
} }
debug("TCP: hash table remove: index %i, sock %i, bucket: %i, new: %p", debug("TCP: hash table remove: index %li, sock %i, bucket: %i, new: %p",
conn - tc, conn->sock, b, conn - tc, conn->sock, b,
prev ? CONN_OR_NULL(prev->next_index) : tc_hash[b]); prev ? CONN_OR_NULL(prev->next_index) : tc_hash[b]);
} }
@ -1421,7 +1421,7 @@ static void tcp_hash_update(struct tcp_conn *old, struct tcp_conn *new)
} }
} }
debug("TCP: hash table update: old index %i, new index %i, sock %i, " debug("TCP: hash table update: old index %li, new index %li, sock %i, "
"bucket: %i, old: %p, new: %p", "bucket: %i, old: %p, new: %p",
old - tc, new - tc, new->sock, b, old, new); old - tc, new - tc, new->sock, b, old, new);
} }
@ -1461,7 +1461,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_conn *hole)
struct tcp_conn *from, *to; struct tcp_conn *from, *to;
if ((hole - tc) == --c->tcp.conn_count) { if ((hole - tc) == --c->tcp.conn_count) {
debug("TCP: hash table compaction: index %i (%p) was max index", debug("TCP: hash table compaction: maximum index was %li (%p)",
hole - tc, hole); hole - tc, hole);
memset(hole, 0, sizeof(*hole)); memset(hole, 0, sizeof(*hole));
return; return;
@ -1475,7 +1475,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_conn *hole)
tcp_epoll_ctl(c, to); tcp_epoll_ctl(c, to);
debug("TCP: hash table compaction: old index %i, new index %i, " debug("TCP: hash table compaction: old index %li, new index %li, "
"sock %i, from: %p, to: %p", "sock %i, from: %p, to: %p",
from - tc, to - tc, from->sock, from, to); from - tc, to - tc, from->sock, from, to);
@ -1500,7 +1500,7 @@ static void tcp_conn_destroy(struct ctx *c, struct tcp_conn *conn)
static void tcp_rst_do(struct ctx *c, struct tcp_conn *conn); static void tcp_rst_do(struct ctx *c, struct tcp_conn *conn);
#define tcp_rst(c, conn) \ #define tcp_rst(c, conn) \
do { \ do { \
debug("TCP: index %i, reset at %s:%i", conn - tc, \ debug("TCP: index %li, reset at %s:%i", conn - tc, \
__func__, __LINE__); \ __func__, __LINE__); \
tcp_rst_do(c, conn); \ tcp_rst_do(c, conn); \
} while (0) } while (0)
@ -2357,7 +2357,7 @@ static int tcp_data_from_sock(struct ctx *c, struct tcp_conn *conn)
if (SEQ_LT(already_sent, 0)) { if (SEQ_LT(already_sent, 0)) {
/* RFC 761, section 2.1. */ /* RFC 761, section 2.1. */
trace("TCP: ACK sequence gap: ACK for %lu, sent: %lu", trace("TCP: ACK sequence gap: ACK for %u, sent: %u",
conn->seq_ack_from_tap, conn->seq_to_tap); conn->seq_ack_from_tap, conn->seq_to_tap);
conn->seq_to_tap = conn->seq_ack_from_tap; conn->seq_to_tap = conn->seq_ack_from_tap;
already_sent = 0; already_sent = 0;
@ -2589,7 +2589,7 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp_conn *conn,
} }
if (retr) { if (retr) {
trace("TCP: fast re-transmit, ACK: %lu, previous sequence: %lu", trace("TCP: fast re-transmit, ACK: %u, previous sequence: %u",
max_ack_seq, conn->seq_to_tap); max_ack_seq, conn->seq_to_tap);
conn->seq_ack_from_tap = max_ack_seq; conn->seq_ack_from_tap = max_ack_seq;
conn->seq_to_tap = max_ack_seq; conn->seq_to_tap = max_ack_seq;
@ -2956,17 +2956,17 @@ static void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
conn_flag(c, conn, ~ACK_TO_TAP_DUE); conn_flag(c, conn, ~ACK_TO_TAP_DUE);
} else if (conn->flags & ACK_FROM_TAP_DUE) { } else if (conn->flags & ACK_FROM_TAP_DUE) {
if (!(conn->events & ESTABLISHED)) { if (!(conn->events & ESTABLISHED)) {
debug("TCP: index %i, handshake timeout", conn - tc); debug("TCP: index %li, handshake timeout", conn - tc);
tcp_rst(c, conn); tcp_rst(c, conn);
} else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) {
debug("TCP: index %i, FIN timeout", conn - tc); debug("TCP: index %li, FIN timeout", conn - tc);
tcp_rst(c, conn); tcp_rst(c, conn);
} else if (conn->retrans == TCP_MAX_RETRANS) { } else if (conn->retrans == TCP_MAX_RETRANS) {
debug("TCP: index %i, maximum retransmissions exceeded", debug("TCP: index %li, retransmissions count exceeded",
conn - tc); conn - tc);
tcp_rst(c, conn); tcp_rst(c, conn);
} else { } else {
debug("TCP: index %i, ACK timeout, retry", conn - tc); debug("TCP: index %li, ACK timeout, retry", conn - tc);
conn->retrans++; conn->retrans++;
conn->seq_to_tap = conn->seq_ack_from_tap; conn->seq_to_tap = conn->seq_ack_from_tap;
tcp_data_from_sock(c, conn); tcp_data_from_sock(c, conn);
@ -2984,7 +2984,7 @@ static void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
*/ */
timerfd_settime(conn->timer, 0, &new, &old); timerfd_settime(conn->timer, 0, &new, &old);
if (old.it_value.tv_sec == ACT_TIMEOUT) { if (old.it_value.tv_sec == ACT_TIMEOUT) {
debug("TCP: index %i, activity timeout", conn - tc); debug("TCP: index %li, activity timeout", conn - tc);
tcp_rst(c, conn); tcp_rst(c, conn);
} }
} }

View file

@ -173,14 +173,14 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
return; return;
conn->flags &= flag; conn->flags &= flag;
debug("TCP (spliced): index %i: %s dropped", (conn) - tc, debug("TCP (spliced): index %li: %s dropped", conn - tc,
tcp_splice_flag_str[fls(~flag)]); tcp_splice_flag_str[fls(~flag)]);
} else { } else {
if (conn->flags & flag) if (conn->flags & flag)
return; return;
conn->flags |= flag; conn->flags |= flag;
debug("TCP (spliced): index %i: %s", (conn) - tc, debug("TCP (spliced): index %li: %s", conn - tc,
tcp_splice_flag_str[fls(flag)]); tcp_splice_flag_str[fls(flag)]);
} }
@ -253,14 +253,14 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
return; return;
conn->events &= event; conn->events &= event;
debug("TCP (spliced): index %i, ~%s", conn - tc, debug("TCP (spliced): index %li, ~%s", conn - tc,
tcp_splice_event_str[fls(~event)]); tcp_splice_event_str[fls(~event)]);
} else { } else {
if (conn->events & event) if (conn->events & event)
return; return;
conn->events |= event; conn->events |= event;
debug("TCP (spliced): index %i, %s", conn - tc, debug("TCP (spliced): index %li, %s", conn - tc,
tcp_splice_event_str[fls(event)]); tcp_splice_event_str[fls(event)]);
} }
@ -286,7 +286,7 @@ static void tcp_table_splice_compact(struct ctx *c,
struct tcp_splice_conn *move; struct tcp_splice_conn *move;
if ((hole - tc) == --c->tcp.splice_conn_count) { if ((hole - tc) == --c->tcp.splice_conn_count) {
debug("TCP (spliced): index %i (max) removed", hole - tc); debug("TCP (spliced): index %li (max) removed", hole - tc);
return; return;
} }
@ -300,7 +300,7 @@ static void tcp_table_splice_compact(struct ctx *c,
move->pipe_b_a[0] = move->pipe_b_a[1] = -1; move->pipe_b_a[0] = move->pipe_b_a[1] = -1;
move->flags = move->events = 0; move->flags = move->events = 0;
debug("TCP (spliced): index %i moved to %i", move - tc, hole - tc); debug("TCP (spliced): index %li moved to %li", move - tc, hole - tc);
tcp_splice_epoll_ctl(c, hole); tcp_splice_epoll_ctl(c, hole);
if (tcp_splice_epoll_ctl(c, hole)) if (tcp_splice_epoll_ctl(c, hole))
conn_flag(c, hole, CLOSING); conn_flag(c, hole, CLOSING);
@ -338,7 +338,7 @@ static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn)
conn->events = CLOSED; conn->events = CLOSED;
conn->flags = 0; conn->flags = 0;
debug("TCP (spliced): index %i, CLOSED", conn - tc); debug("TCP (spliced): index %li, CLOSED", conn - tc);
tcp_table_splice_compact(c, conn); tcp_table_splice_compact(c, conn);
} }