From: Nadav Har'El <n...@scylladb.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Fix warning in route.cc

In route.cc we have code which writes some socket addresses to a routing
socket. The write is supposed to be 8-byte aligned length, and the code
also *reads* a multiple of 8 bytes, even though the actual structure may
be shorter. Gcc 8 discovers this inconsistency (reading 56 bytes from a
structure known to be 54 bytes long) and complains.

The fix is to size the length of the copy correctly, and only 8-byte-align
the cursor of the write.

Other than quieting the compiler, this change shouldn't fix any real bug.

Fixes #958

Signed-off-by: Nadav Har'El <n...@scylladb.com>

---
diff --git a/bsd/porting/route.cc b/bsd/porting/route.cc
--- a/bsd/porting/route.cc
+++ b/bsd/porting/route.cc
@@ -153,8 +153,13 @@ static struct mbuf* osv_route_arp_rtmsg(int if_idx, int cmd, const char* ip,
     m_rtmsg->m_rtm.rtm_seq = ++msg_seq;
     m_rtmsg->m_rtm.rtm_addrs = (RTA_GATEWAY | RTA_DST);

+    // Note that (((struct bsd_sockaddr *)(sa))->sa_len) is the real
+    // length of the address structure, but in the routing socket we're
+    // supposed to round the length to multiples of 8 bytes (long).
+    // We still can't *copy* this much from the input address structure,
+    // because the compiler (starting from gcc 8) would warn about it.
 #define CP_ADDR(w, sa) \
-    l = SA_SIZE_ALWAYS(&(sa)); bcopy(&(sa), cp, l); cp += l;\
+ l = SA_SIZE_ALWAYS(&(sa)); bcopy(&(sa), cp, (((struct bsd_sockaddr *)(&(sa)))->sa_len)); cp += l;\

     CP_ADDR(RTA_DST, dst);
     CP_ADDR(RTA_GATEWAY, sdl_m);

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to