summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-07-22 20:27:39 +0200
committerThomas Haller <thaller@redhat.com>2022-07-26 12:27:58 +0200
commit51625013d4bc610569422ad22f824a82a92a21e1 (patch)
tree4aac19eec3eceb88e424d905e5dc028bd22a9bd2
parent2c70fef12e35c8cedfaee7bad837a94fe314ac90 (diff)
downloadNetworkManager-51625013d4bc610569422ad22f824a82a92a21e1.tar.gz
glib-aux: add code comment to nm_ip_addr_set() about using it for NMIPAddr argument
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 6cdc8875ef..20810e4cd5 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -277,8 +277,15 @@ nm_ip_addr_set(int addr_family, gpointer dst, gconstpointer src)
nm_assert(dst);
nm_assert(src);
- /* this MUST use memcpy() (or similar means) to support unaligned src/dst pointers. */
+ /* this MUST use memcpy() to support unaligned src/dst pointers. */
memcpy(dst, src, nm_utils_addr_family_to_size(addr_family));
+
+ /* Note that @dst is not necessarily a NMIPAddr, it could also be just
+ * an in_addr_t/struct in6_addr. We thus can only set the bytes that
+ * we know are present based on the address family.
+ *
+ * Using this function to initialize an NMIPAddr union (for IPv4) leaves
+ * uninitalized bytes. Avoid that by using nm_ip_addr_init() instead. */
}
static inline NMIPAddr
@@ -291,6 +298,8 @@ nm_ip_addr_init(int addr_family, gconstpointer src)
G_STATIC_ASSERT_EXPR(sizeof(NMIPAddr) == sizeof(struct in6_addr));
+ /* this MUST use memcpy() to support unaligned src/dst pointers. */
+
if (NM_IS_IPv4(addr_family)) {
memcpy(&a, src, sizeof(in_addr_t));