git: 4e61f158893b - stable/14 - debugnet: Use precise types when accessing mbuf contents

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sat, 19 Oct 2024 12:56:29 UTC
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e61f158893b4fcd95a93ccee3812e395378feef

commit 4e61f158893b4fcd95a93ccee3812e395378feef
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-10-09 15:28:57 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-10-18 12:28:09 +0000

    debugnet: Use precise types when accessing mbuf contents
    
    This might be useful when adding bounds checks to mtod().  No functional
    change intended.
    
    MFC after:      1 week
    
    (cherry picked from commit 5c385a54fe9ccbd3f28f20b5a025a856d229fa05)
---
 sys/net/debugnet.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys/net/debugnet.c b/sys/net/debugnet.c
index c6f57ec84618..07906e724cbb 100644
--- a/sys/net/debugnet.c
+++ b/sys/net/debugnet.c
@@ -199,7 +199,7 @@ debugnet_udp_output(struct debugnet_pcb *pcb, struct mbuf *m)
 		return (ENOBUFS);
 	}
 
-	udp = mtod(m, void *);
+	udp = mtod(m, struct udphdr *);
 	udp->uh_ulen = htons(m->m_pkthdr.len);
 	/* Use this src port so that the server can connect() the socket */
 	udp->uh_sport = htons(pcb->dp_client_port);
@@ -226,7 +226,7 @@ debugnet_ack_output(struct debugnet_pcb *pcb, uint32_t seqno /* net endian */)
 	m->m_len = sizeof(*dn_ack);
 	m->m_pkthdr.len = sizeof(*dn_ack);
 	MH_ALIGN(m, sizeof(*dn_ack));
-	dn_ack = mtod(m, void *);
+	dn_ack = mtod(m, struct debugnet_ack *);
 	dn_ack->da_seqno = seqno;
 
 	return (debugnet_udp_output(pcb, m));
@@ -400,7 +400,7 @@ debugnet_handle_rx_msg(struct debugnet_pcb *pcb, struct mbuf **mb)
 		}
 	}
 
-	dnh = mtod(m, const void *);
+	dnh = mtod(m, const struct debugnet_msg_hdr *);
 	if (ntohl(dnh->mh_len) + sizeof(*dnh) > m->m_pkthdr.len) {
 		DNETDEBUG("Dropping short packet.\n");
 		return;
@@ -459,7 +459,7 @@ debugnet_handle_ack(struct debugnet_pcb *pcb, struct mbuf **mb, uint16_t sport)
 			return;
 		}
 	}
-	dn_ack = mtod(m, const void *);
+	dn_ack = mtod(m, const struct debugnet_ack *);
 
 	/* Debugnet processing. */
 	/*
@@ -503,7 +503,7 @@ debugnet_handle_udp(struct debugnet_pcb *pcb, struct mbuf **mb)
 			return;
 		}
 	}
-	udp = mtod(m, const void *);
+	udp = mtod(m, const struct udphdr *);
 
 	/* We expect to receive UDP packets on the configured client port. */
 	if (ntohs(udp->uh_dport) != pcb->dp_client_port) {