1
0
mirror of https://passt.top/passt synced 2024-07-01 23:42:41 +00:00

passt: Address warnings from Clang's scan-build

All false positives so far.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-10-19 19:18:04 +02:00
parent 1a563a0cbd
commit b0b77118fe
4 changed files with 53 additions and 38 deletions

6
conf.c
View File

@ -323,7 +323,9 @@ static void get_dns(struct ctx *c)
if (end)
*end = 0;
p = strtok(buf, " \t");
if (!strtok(buf, " \t"))
continue;
while (s - c->dns_search < ARRAY_SIZE(c->dns_search) - 1
&& (p = strtok(NULL, " \t"))) {
strncpy(s->n, p, sizeof(c->dns_search[0]));
@ -371,7 +373,7 @@ static int conf_ns_opt(struct ctx *c,
char *nsdir, char *conf_userns, const char *optarg)
{
int ufd = 0, nfd = 0, try, ret, netns_only_reset = c->netns_only;
char userns[PATH_MAX], netns[PATH_MAX];
char userns[PATH_MAX] = { 0 }, netns[PATH_MAX];
char *endptr;
pid_t pid;

View File

@ -99,15 +99,19 @@ struct opt_server_id {
uint8_t duid_lladdr[ETH_ALEN];
};
static const struct opt_server_id server_id_const = {
{ OPT_SERVERID, OPT_SIZE(server_id) },
#if __BYTE_ORDER == __BIG_ENDIAN
DUID_TYPE_LLT, ARPHRD_ETHER,
#define SERVER_ID { \
{ OPT_SERVERID, OPT_SIZE(server_id) }, \
DUID_TYPE_LLT, ARPHRD_ETHER, 0, { 0 } \
}
#else
__bswap_constant_16(DUID_TYPE_LLT), __bswap_constant_16(ARPHRD_ETHER),
#define SERVER_ID { \
{ OPT_SERVERID, OPT_SIZE(server_id) }, \
__bswap_constant_16(DUID_TYPE_LLT), \
__bswap_constant_16(ARPHRD_ETHER), \
0, { 0 } \
}
#endif
0, { 0 }
};
/**
* struct opt_ia_na - Identity Association for Non-temporary Addresses Option
@ -200,13 +204,11 @@ struct msg_hdr {
uint32_t xid:24;
} __attribute__((__packed__));
static const struct udphdr uh_resp = {
#if __BYTE_ORDER == __BIG_ENDIAN
547, 546, 0, 0,
#define UH_RESP { 547, 546, 0, 0, }
#else
__bswap_constant_16(547), __bswap_constant_16(546), 0, 0,
#define UH_RESP { __bswap_constant_16(547), __bswap_constant_16(546), 0, 0 }
#endif
};
/**
* struct resp_t - Normal advertise and reply message
@ -230,9 +232,9 @@ static struct resp_t {
struct opt_dns_servers dns_servers;
struct opt_dns_search dns_search;
} __attribute__((__packed__)) resp = {
uh_resp,
UH_RESP,
{ 0 },
server_id_const,
SERVER_ID,
{ { OPT_IA_NA, OPT_SIZE_CONV(sizeof(struct opt_ia_na) +
sizeof(struct opt_ia_addr) -
@ -278,9 +280,9 @@ static struct resp_not_on_link_t {
uint8_t var[sizeof(struct opt_ia_na) + sizeof(struct opt_status_code) +
sizeof(struct opt_client_id)];
} __attribute__((__packed__)) resp_not_on_link = {
uh_resp,
UH_RESP,
{ TYPE_REPLY, 0 },
server_id_const,
SERVER_ID,
{ 0, },
};
@ -390,6 +392,7 @@ static size_t dhcpv6_dns_fill(struct ctx *c, char *buf, int offset)
{
struct opt_dns_servers *srv = NULL;
struct opt_dns_search *srch = NULL;
char *p = NULL;
int i;
for (i = 0; !IN6_IS_ADDR_UNSPECIFIED(&c->dns6[i]); i++) {
@ -409,8 +412,6 @@ static size_t dhcpv6_dns_fill(struct ctx *c, char *buf, int offset)
srv->hdr.l = htons(srv->hdr.l);
for (i = 0; *c->dns_search[i].n; i++) {
char *p;
if (!i) {
srch = (struct opt_dns_search *)(buf + offset);
offset += sizeof(struct opt_hdr);

37
tcp.c
View File

@ -2910,48 +2910,53 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
ref_conn.s = conn->sock = s;
if (ref.tcp.v6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa;
struct sockaddr_in6 sa6;
if (IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr) ||
!memcmp(&sa6->sin6_addr, &c->addr6_seen, sizeof(c->gw6)) ||
!memcmp(&sa6->sin6_addr, &c->addr6, sizeof(c->gw6)))
memcpy(&sa6->sin6_addr, &c->gw6, sizeof(c->gw6));
memcpy(&sa6, &sa, sizeof(sa6));
memcpy(&conn->a.a6, &sa6->sin6_addr, sizeof(conn->a.a6));
if (IN6_IS_ADDR_LOOPBACK(&sa6.sin6_addr) ||
!memcmp(&sa6.sin6_addr, &c->addr6_seen, sizeof(c->gw6)) ||
!memcmp(&sa6.sin6_addr, &c->addr6, sizeof(c->gw6)))
memcpy(&sa6.sin6_addr, &c->gw6, sizeof(c->gw6));
conn->sock_port = ntohs(sa6->sin6_port);
memcpy(&conn->a.a6, &sa6.sin6_addr, sizeof(conn->a.a6));
conn->sock_port = ntohs(sa6.sin6_port);
conn->tap_port = ref.tcp.index;
conn->seq_to_tap = tcp_seq_init(c, AF_INET6, &sa6->sin6_addr,
conn->seq_to_tap = tcp_seq_init(c, AF_INET6, &sa6.sin6_addr,
conn->sock_port,
conn->tap_port,
now);
conn->seq_init_to_tap = conn->seq_to_tap;
tcp_hash_insert(c, conn, AF_INET6, &sa6->sin6_addr);
tcp_hash_insert(c, conn, AF_INET6, &sa6.sin6_addr);
} else {
struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa;
in_addr_t s_addr = ntohl(sa4->sin_addr.s_addr);
struct sockaddr_in sa4;
in_addr_t s_addr;
memcpy(&sa4, &sa, sizeof(sa4));
s_addr = sa4.sin_addr.s_addr;
memset(&conn->a.a4.zero, 0, sizeof(conn->a.a4.zero));
memset(&conn->a.a4.one, 0xff, sizeof(conn->a.a4.one));
if (s_addr >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET ||
s_addr == INADDR_ANY || s_addr == htonl(c->addr4_seen))
sa4->sin_addr.s_addr = c->gw4;
sa4.sin_addr.s_addr = c->gw4;
memcpy(&conn->a.a4.a, &sa4->sin_addr, sizeof(conn->a.a4.a));
memcpy(&conn->a.a4.a, &s_addr, sizeof(conn->a.a4.a));
conn->sock_port = ntohs(sa4->sin_port);
conn->sock_port = ntohs(sa4.sin_port);
conn->tap_port = ref.tcp.index;
conn->seq_to_tap = tcp_seq_init(c, AF_INET, &sa4->sin_addr,
conn->seq_to_tap = tcp_seq_init(c, AF_INET, &s_addr,
conn->sock_port,
conn->tap_port,
now);
conn->seq_init_to_tap = conn->seq_to_tap;
tcp_hash_insert(c, conn, AF_INET, &sa4->sin_addr);
tcp_hash_insert(c, conn, AF_INET, &s_addr);
}
conn->seq_ack_from_tap = conn->seq_to_tap + 1;

15
udp.c
View File

@ -461,10 +461,17 @@ int udp_splice_connect(struct ctx *c, int v6, int bound_sock,
if (getsockname(s, (struct sockaddr *)&sa, &sl))
goto fail;
if (v6)
ref.udp.port = ntohs(((struct sockaddr_in6 *)&sa)->sin6_port);
else
ref.udp.port = ntohs(((struct sockaddr_in *)&sa)->sin_port);
if (v6) {
struct sockaddr_in6 sa6;
memcpy(&sa6, &sa, sizeof(sa6));
ref.udp.port = ntohs(sa6.sin6_port);
} else {
struct sockaddr_in sa4;
memcpy(&sa4, &sa, sizeof(sa4));
ref.udp.port = ntohs(sa4.sin_port);
}
sp = &udp_splice_map[v6 ? V6 : V4][ref.udp.port];
if (splice == UDP_BACK_TO_INIT) {