mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 06:30:08 +01:00
glib-aux: use uint32 type for prefix length parameter
Of course, the prefix length cannot be larger than 32 or 128. But as C does implicit conversions, a buggy prefix length can lead to a (wrongly) valid prefix length. Make the type uint32, to prevent that (at least for common cases, unless you pass a huge 64 bit integer).
This commit is contained in:
parent
b5a06dedd4
commit
0cf9db42d4
2 changed files with 11 additions and 10 deletions
|
|
@ -6282,7 +6282,7 @@ _nm_utils_ssid_to_string_gbytes(GBytes *ssid)
|
|||
/*****************************************************************************/
|
||||
|
||||
gconstpointer
|
||||
nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen)
|
||||
nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen)
|
||||
{
|
||||
g_return_val_if_fail(dst, NULL);
|
||||
|
||||
|
|
@ -6308,7 +6308,8 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer
|
|||
|
||||
/* nm_utils_ip6_address_clear_host_address:
|
||||
* @dst: destination output buffer, will contain the network part of the @src address
|
||||
* @src: source ip6 address
|
||||
* @src: source ip6 address. If NULL, this does an in-place update of @dst.
|
||||
* Also, @src and @dst are allowed to be the same pointers.
|
||||
* @plen: prefix length of network
|
||||
*
|
||||
* Note: this function is self assignment safe, to update @src inplace, set both
|
||||
|
|
@ -6317,7 +6318,7 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer
|
|||
const struct in6_addr *
|
||||
nm_utils_ip6_address_clear_host_address(struct in6_addr *dst,
|
||||
const struct in6_addr *src,
|
||||
guint8 plen)
|
||||
guint32 plen)
|
||||
{
|
||||
g_return_val_if_fail(plen <= 128, NULL);
|
||||
g_return_val_if_fail(dst, NULL);
|
||||
|
|
@ -6346,7 +6347,7 @@ nm_utils_ip6_address_clear_host_address(struct in6_addr *dst,
|
|||
int
|
||||
nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a,
|
||||
const struct in6_addr *addr_b,
|
||||
guint8 plen)
|
||||
guint32 plen)
|
||||
{
|
||||
int nbytes;
|
||||
guint8 va, vb, m;
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ guint32 _nm_utils_ip4_get_default_prefix0(in_addr_t ip);
|
|||
guint32 _nm_utils_ip4_get_default_prefix(in_addr_t ip);
|
||||
|
||||
gconstpointer
|
||||
nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen);
|
||||
nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint32 plen);
|
||||
|
||||
/* nm_utils_ip4_address_clear_host_address:
|
||||
* @addr: source ip6 address
|
||||
|
|
@ -414,17 +414,17 @@ nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer
|
|||
* returns: the input address, with the host address set to 0.
|
||||
*/
|
||||
static inline in_addr_t
|
||||
nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen)
|
||||
nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint32 plen)
|
||||
{
|
||||
return addr & _nm_utils_ip4_prefix_to_netmask(plen);
|
||||
}
|
||||
|
||||
const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr *dst,
|
||||
const struct in6_addr *src,
|
||||
guint8 plen);
|
||||
guint32 plen);
|
||||
|
||||
static inline int
|
||||
nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint8 plen)
|
||||
nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint32 plen)
|
||||
{
|
||||
NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)),
|
||||
htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen)));
|
||||
|
|
@ -433,10 +433,10 @@ nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint8
|
|||
|
||||
int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a,
|
||||
const struct in6_addr *addr_b,
|
||||
guint8 plen);
|
||||
guint32 plen);
|
||||
|
||||
static inline gboolean
|
||||
nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint8 plen)
|
||||
nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint32 plen)
|
||||
{
|
||||
return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue