[glib: 1/2] gsocket: Add assertions about socket address sizes for memcpy()




commit ff944776fe2760570ee923a5e2add28c40d003bd
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Apr 27 14:47:35 2022 +0100

    gsocket: Add assertions about socket address sizes for memcpy()
    
    These `memcpy()` calls only happen if `g_inet_address_get_family(group)
    == G_SOCKET_FAMILY_IPV4`, so the assertions should never fail.
    
    It’s helpful for understanding the code, and for static analysis, to add
    the assertions though.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Coverity CID: #1486858

 gio/gsocket.c | 4 ++++
 1 file changed, 4 insertions(+)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index b19a9a3731..a582bb6966 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -2604,8 +2604,12 @@ g_socket_multicast_group_operation_ssm (GSocket       *socket,
             S_ADDR_FIELD(mc_req_src) = iface_addr->sin_addr.s_addr;
 #endif  /* defined(G_OS_WIN32) && defined (HAVE_IF_NAMETOINDEX) */
           }
+
+        g_assert (g_inet_address_get_native_size (group) == sizeof (mc_req_src.imr_multiaddr));
         memcpy (&mc_req_src.imr_multiaddr, g_inet_address_to_bytes (group),
                 g_inet_address_get_native_size (group));
+
+        g_assert (g_inet_address_get_native_size (source_specific) == sizeof (mc_req_src.imr_sourceaddr));
         memcpy (&mc_req_src.imr_sourceaddr,
                 g_inet_address_to_bytes (source_specific),
                 g_inet_address_get_native_size (source_specific));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]