kernel-netlink: Fix compiler warnings with strncpy()

Normally, GCC sees that we terminate the destination with a zero byte.
However, when using `-fsanitize=address`, there seems to be additional
instrumentation code after strncpy() so GCC produces warnings like
these:

‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
This commit is contained in:
Tobias Brunner
2022-09-15 12:16:12 +02:00
parent ae9d110dd9
commit eab9cd8661
2 changed files with 14 additions and 14 deletions
@@ -1411,7 +1411,7 @@ static void netlink_find_offload_feature(const char *ifname)
.cmd = ETHTOOL_GSSET_INFO,
.sset_mask = 1ULL << ETH_SS_FEATURES,
);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ifr.ifr_data = (void*)sset_info;
@@ -1427,7 +1427,7 @@ static void netlink_find_offload_feature(const char *ifname)
.cmd = ETHTOOL_GSTRINGS,
.string_set = ETH_SS_FEATURES,
);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ifr.ifr_data = (void*)cmd;
@@ -1486,7 +1486,7 @@ static bool netlink_detect_offload(const char *ifname)
.cmd = ETHTOOL_GFEATURES,
.size = netlink_hw_offload.total_blocks,
);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ifr.ifr_data = (void*)cmd;
@@ -1778,8 +1778,8 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
}
algo->alg_key_len = data->enc_key.len * 8;
algo->alg_icv_len = icv_size;
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name));
algo->alg_name[sizeof(algo->alg_name) - 1] = '\0';
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name)-1);
algo->alg_name[sizeof(algo->alg_name)-1] = '\0';
memcpy(algo->alg_key, data->enc_key.ptr, data->enc_key.len);
break;
}
@@ -1805,8 +1805,8 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
goto failed;
}
algo->alg_key_len = data->enc_key.len * 8;
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name));
algo->alg_name[sizeof(algo->alg_name) - 1] = '\0';
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name)-1);
algo->alg_name[sizeof(algo->alg_name)-1] = '\0';
memcpy(algo->alg_key, data->enc_key.ptr, data->enc_key.len);
}
}
@@ -1862,8 +1862,8 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
}
algo->alg_key_len = data->int_key.len * 8;
algo->alg_trunc_len = trunc_len;
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name));
algo->alg_name[sizeof(algo->alg_name) - 1] = '\0';
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name)-1);
algo->alg_name[sizeof(algo->alg_name)-1] = '\0';
memcpy(algo->alg_key, data->int_key.ptr, data->int_key.len);
}
else
@@ -1877,8 +1877,8 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
goto failed;
}
algo->alg_key_len = data->int_key.len * 8;
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name));
algo->alg_name[sizeof(algo->alg_name) - 1] = '\0';
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name)-1);
algo->alg_name[sizeof(algo->alg_name)-1] = '\0';
memcpy(algo->alg_key, data->int_key.ptr, data->int_key.len);
}
}
@@ -1904,8 +1904,8 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
goto failed;
}
algo->alg_key_len = 0;
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name));
algo->alg_name[sizeof(algo->alg_name) - 1] = '\0';
strncpy(algo->alg_name, alg_name, sizeof(algo->alg_name)-1);
algo->alg_name[sizeof(algo->alg_name)-1] = '\0';
}
if (data->encap)
@@ -1126,7 +1126,7 @@ static void process_link(private_kernel_netlink_net_t *this,
);
this->ifaces->insert_last(this->ifaces, entry);
}
strncpy(entry->ifname, name, IFNAMSIZ);
strncpy(entry->ifname, name, IFNAMSIZ-1);
entry->ifname[IFNAMSIZ-1] = '\0';
entry->usable = charon->kernel->is_interface_usable(charon->kernel,
name);