From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 01/16] treewide: Invalid type in argument to printf format specifier, CWE-686 Date: Tue, 05 Apr 2022 19:04:59 +0200 Message-ID: <20220405170514.2963773-2-sbrivio@redhat.com> In-Reply-To: <20220405170514.2963773-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6540830853170221989==" --===============6540830853170221989== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Harmless except for two bad debugging prints. Signed-off-by: Stefano Brivio --- packet.c | 6 +++--- pcap.c | 6 +++--- tcp.c | 38 +++++++++++++++++++------------------- tcp_splice.c | 14 +++++++------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packet.c b/packet.c index d003640..fa9e9b4 100644 --- a/packet.c +++ b/packet.c @@ -53,12 +53,12 @@ void packet_add_do(struct pool *p, size_t len, const char= *start, } =20 if (len > UINT16_MAX) { - trace("add packet length %lu, %s:%i", func, line); + trace("add packet length %lu, %s:%i", len, func, line); return; } =20 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); return; } @@ -111,7 +111,7 @@ void *packet_get_do(const struct pool *p, size_t index, s= ize_t offset, =20 if (len + offset > p->pkt[index].len) { 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, func, line); } diff --git a/pcap.c b/pcap.c index 296bbb5..64beb34 100644 --- a/pcap.c +++ b/pcap.c @@ -88,7 +88,7 @@ void pcap(const char *pkt, size_t len) h.caplen =3D h.len =3D len; =20 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); } =20 /** @@ -123,7 +123,7 @@ void pcapm(const struct msghdr *mh) =20 return; fail: - debug("Cannot log packet, length %u", iov->iov_len - 4); + debug("Cannot log packet, length %lu", iov->iov_len - 4); } =20 /** @@ -161,7 +161,7 @@ void pcapmm(const struct mmsghdr *mmh, unsigned int vlen) } return; fail: - debug("Cannot log packet, length %u", iov->iov_len - 4); + debug("Cannot log packet, length %lu", iov->iov_len - 4); } =20 /** diff --git a/tcp.c b/tcp.c index 2194067..1409c53 100644 --- a/tcp.c +++ b/tcp.c @@ -848,7 +848,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp= _conn *conn) it.it_value.tv_sec =3D ACT_TIMEOUT; } =20 - 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); =20 timerfd_settime(conn->timer, 0, &it, NULL); @@ -868,14 +868,14 @@ static void conn_flag_do(const struct ctx *c, struct tc= p_conn *conn, return; =20 conn->flags &=3D flag; - debug("TCP: index %i: %s dropped", (conn) - tc, + debug("TCP: index %li: %s dropped", conn - tc, tcp_flag_str[fls(~flag)]); } else { if (conn->flags & flag) return; =20 conn->flags |=3D flag; - debug("TCP: index %i: %s", (conn) - tc, + debug("TCP: index %li: %s", conn - tc, tcp_flag_str[fls(flag)]); } =20 @@ -924,12 +924,12 @@ static void conn_event_do(const struct ctx *c, struct t= cp_conn *conn, new +=3D 5; =20 if (prev !=3D new) { - debug("TCP: index %i, %s: %s -> %s", (conn) - tc, + debug("TCP: index %li, %s: %s -> %s", conn - tc, num =3D=3D -1 ? "CLOSED" : tcp_event_str[num], prev =3D=3D -1 ? "CLOSED" : tcp_state_str[prev], (new =3D=3D -1 || num =3D=3D -1) ? "CLOSED" : tcp_state_str[new]); } else { - debug("TCP: index %i, %s", (conn) - tc, + debug("TCP: index %li, %s", conn - tc, num =3D=3D -1 ? "CLOSED" : tcp_event_str[num]); } =20 @@ -1371,8 +1371,8 @@ static void tcp_hash_insert(const struct ctx *c, struct= tcp_conn *conn, tc_hash[b] =3D conn; conn->hash_bucket =3D b; =20 - debug("TCP: hash table insert: index %i, sock %i, bucket: %i, next: %p", - conn - tc, conn->sock, b, CONN_OR_NULL(conn->next_index)); + debug("TCP: hash table insert: index %li, sock %i, bucket: %i, next: " + "%p", conn - tc, conn->sock, b, CONN_OR_NULL(conn->next_index)); } =20 /** @@ -1395,7 +1395,7 @@ static void tcp_hash_remove(const struct tcp_conn *conn) } } =20 - 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, prev ? CONN_OR_NULL(prev->next_index) : tc_hash[b]); } @@ -1421,7 +1421,7 @@ static void tcp_hash_update(struct tcp_conn *old, struc= t tcp_conn *new) } } =20 - 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", 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; =20 if ((hole - tc) =3D=3D --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); memset(hole, 0, sizeof(*hole)); return; @@ -1475,7 +1475,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp= _conn *hole) =20 tcp_epoll_ctl(c, to); =20 - 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", from - tc, to - tc, from->sock, from, to); =20 @@ -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); #define tcp_rst(c, conn) \ do { \ - debug("TCP: index %i, reset at %s:%i", conn - tc, \ + debug("TCP: index %li, reset at %s:%i", conn - tc, \ __func__, __LINE__); \ tcp_rst_do(c, conn); \ } while (0) @@ -2357,7 +2357,7 @@ static int tcp_data_from_sock(struct ctx *c, struct tcp= _conn *conn) =20 if (SEQ_LT(already_sent, 0)) { /* 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_to_tap =3D conn->seq_ack_from_tap; already_sent =3D 0; @@ -2589,7 +2589,7 @@ static void tcp_data_from_tap(struct ctx *c, struct tcp= _conn *conn, } =20 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); conn->seq_ack_from_tap =3D max_ack_seq; conn->seq_to_tap =3D max_ack_seq; @@ -2956,17 +2956,17 @@ static void tcp_timer_handler(struct ctx *c, union ep= oll_ref ref) conn_flag(c, conn, ~ACK_TO_TAP_DUE); } else if (conn->flags & ACK_FROM_TAP_DUE) { if (!(conn->events & ESTABLISHED)) { - debug("TCP: index %i, handshake timeout", conn - tc); + debug("TCP: index %li, handshake timeout", conn - tc); tcp_rst(c, conn); } 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); } else if (conn->retrans =3D=3D TCP_MAX_RETRANS) { - debug("TCP: index %i, maximum retransmissions exceeded", + debug("TCP: index %li, retransmissions count exceeded", conn - tc); tcp_rst(c, conn); } else { - debug("TCP: index %i, ACK timeout, retry", conn - tc); + debug("TCP: index %li, ACK timeout, retry", conn - tc); conn->retrans++; conn->seq_to_tap =3D conn->seq_ack_from_tap; tcp_data_from_sock(c, conn); @@ -2984,7 +2984,7 @@ static void tcp_timer_handler(struct ctx *c, union epol= l_ref ref) */ timerfd_settime(conn->timer, 0, &new, &old); if (old.it_value.tv_sec =3D=3D ACT_TIMEOUT) { - debug("TCP: index %i, activity timeout", conn - tc); + debug("TCP: index %li, activity timeout", conn - tc); tcp_rst(c, conn); } } diff --git a/tcp_splice.c b/tcp_splice.c index 3f2ef2e..24a3b4b 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -173,14 +173,14 @@ static void conn_flag_do(const struct ctx *c, struct tc= p_splice_conn *conn, return; =20 conn->flags &=3D 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)]); } else { if (conn->flags & flag) return; =20 conn->flags |=3D flag; - debug("TCP (spliced): index %i: %s", (conn) - tc, + debug("TCP (spliced): index %li: %s", conn - tc, tcp_splice_flag_str[fls(flag)]); } =20 @@ -253,14 +253,14 @@ static void conn_event_do(const struct ctx *c, struct t= cp_splice_conn *conn, return; =20 conn->events &=3D event; - debug("TCP (spliced): index %i, ~%s", conn - tc, + debug("TCP (spliced): index %li, ~%s", conn - tc, tcp_splice_event_str[fls(~event)]); } else { if (conn->events & event) return; =20 conn->events |=3D event; - debug("TCP (spliced): index %i, %s", conn - tc, + debug("TCP (spliced): index %li, %s", conn - tc, tcp_splice_event_str[fls(event)]); } =20 @@ -286,7 +286,7 @@ static void tcp_table_splice_compact(struct ctx *c, struct tcp_splice_conn *move; =20 if ((hole - tc) =3D=3D --c->tcp.splice_conn_count) { - debug("TCP (spliced): index %i (max) removed", hole - tc); + debug("TCP (spliced): index %li (max) removed", hole - tc); return; } =20 @@ -300,7 +300,7 @@ static void tcp_table_splice_compact(struct ctx *c, move->pipe_b_a[0] =3D move->pipe_b_a[1] =3D -1; move->flags =3D move->events =3D 0; =20 - 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); if (tcp_splice_epoll_ctl(c, hole)) conn_flag(c, hole, CLOSING); @@ -338,7 +338,7 @@ static void tcp_splice_destroy(struct ctx *c, struct tcp_= splice_conn *conn) =20 conn->events =3D CLOSED; conn->flags =3D 0; - debug("TCP (spliced): index %i, CLOSED", conn - tc); + debug("TCP (spliced): index %li, CLOSED", conn - tc); =20 tcp_table_splice_compact(c, conn); } --=20 2.35.1 --===============6540830853170221989==--