Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ldpd ldpd(8): Fix address of misaligned packed memb...
details: https://anonhg.NetBSD.org/src/rev/713b0c8b33f6
branches: trunk
changeset: 368170:713b0c8b33f6
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Jun 26 17:55:38 2022 +0000
description:
ldpd(8): Fix address of misaligned packed members.
PR kern/56895
diffstat:
usr.sbin/ldpd/Makefile | 5 +----
usr.sbin/ldpd/fsm.c | 15 +++++++++------
usr.sbin/ldpd/ldp_peer.c | 9 +++++----
usr.sbin/ldpd/socketops.c | 11 ++++++++---
4 files changed, 23 insertions(+), 17 deletions(-)
diffs (153 lines):
diff -r 5988b4ea4b6b -r 713b0c8b33f6 usr.sbin/ldpd/Makefile
--- a/usr.sbin/ldpd/Makefile Sun Jun 26 17:55:24 2022 +0000
+++ b/usr.sbin/ldpd/Makefile Sun Jun 26 17:55:38 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2021/02/23 15:05:08 joerg Exp $
+# $NetBSD: Makefile,v 1.8 2022/06/26 17:55:38 riastradh Exp $
.include <bsd.own.mk>
@@ -26,7 +26,4 @@
CPPFLAGS+=-DINET6
.endif
-CWARNFLAGS.clang+= -Wno-error=address-of-packed-member
-CWARNFLAGS.gcc+= ${GCC_NO_ADDR_OF_PACKED_MEMBER}
-
.include <bsd.prog.mk>
diff -r 5988b4ea4b6b -r 713b0c8b33f6 usr.sbin/ldpd/fsm.c
--- a/usr.sbin/ldpd/fsm.c Sun Jun 26 17:55:24 2022 +0000
+++ b/usr.sbin/ldpd/fsm.c Sun Jun 26 17:55:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fsm.c,v 1.15 2014/03/18 18:20:47 riastradh Exp $ */
+/* $NetBSD: fsm.c,v 1.16 2022/06/26 17:55:38 riastradh Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -59,6 +59,7 @@
const struct transport_address_tlv *trtlv;
struct hello_info *hi = NULL;
union sockunion traddr;
+ struct in_addr ldp_id;
if ((!pduid) || (!ht))
return;
@@ -125,7 +126,8 @@
hi->keepalive = LDP_THELLO_KEEP;
}
- if (!get_ldp_peer_by_id(&pduid->ldp_id)) {
+ ldp_id = pduid->ldp_id;
+ if (!get_ldp_peer_by_id(&ldp_id)) {
/*
* RFC 5036 2.5.2: If A1 > A2, LSR1 plays the active role;
* otherwise it is passive.
@@ -134,7 +136,7 @@
(hi->transport_address.sa.sa_family == AF_INET &&
ntohl(hi->transport_address.sin.sin_addr.s_addr) <
ntohl(ladd->s_addr))) {
- peer = ldp_peer_new(&pduid->ldp_id, padd,
+ peer = ldp_peer_new(&ldp_id, padd,
&hi->transport_address.sa,
ntohs(ht->ch.holdtime), 0);
if (peer == NULL)
@@ -151,7 +153,7 @@
struct address_list_tlv *t;
struct ifaddrs *ifa, *ifb;
struct sockaddr_in *sa;
- struct in_addr *ia;
+ char *ia;
uint16_t adrcount = 0;
if (getifaddrs(&ifa) == -1)
@@ -184,7 +186,7 @@
adrcount * sizeof(struct in_addr));
t->a_af = htons(LDP_AF_INET);
- ia = &t->a_address;
+ ia = (void *)&t->a_address;
for (adrcount = 0, ifb = ifa; ifb; ifb = ifb->ifa_next) {
if ((ifb->ifa_addr->sa_family != AF_INET) ||
(!(ifb->ifa_flags & IFF_UP)))
@@ -192,7 +194,8 @@
sa = (struct sockaddr_in *) ifb->ifa_addr;
if (ntohl(sa->sin_addr.s_addr) >> 24 == IN_LOOPBACKNET)
continue;
- memcpy(&ia[adrcount], &sa->sin_addr, sizeof(struct in_addr));
+ memcpy(ia + adrcount*sizeof(struct in_addr), &sa->sin_addr,
+ sizeof(struct in_addr));
adrcount++;
}
freeifaddrs(ifa);
diff -r 5988b4ea4b6b -r 713b0c8b33f6 usr.sbin/ldpd/ldp_peer.c
--- a/usr.sbin/ldpd/ldp_peer.c Sun Jun 26 17:55:24 2022 +0000
+++ b/usr.sbin/ldpd/ldp_peer.c Sun Jun 26 17:55:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_peer.c,v 1.18 2020/06/22 07:50:53 msaitoh Exp $ */
+/* $NetBSD: ldp_peer.c,v 1.19 2022/06/26 17:55:38 riastradh Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -307,7 +307,7 @@
add_ifaddresses(struct ldp_peer * p, const struct al_tlv * a)
{
int i, c, n;
- const struct in_addr *ia;
+ const char *ia;
struct sockaddr_in ipa;
memset(&ipa, 0, sizeof(ipa));
@@ -329,8 +329,9 @@
debugp("Trying to add %d addresses to peer %s ... \n", n,
inet_ntoa(p->ldp_id));
- for (ia = (const struct in_addr *) & a->address,c = 0,i = 0; i<n; i++) {
- memcpy(&ipa.sin_addr, &ia[i], sizeof(ipa.sin_addr));
+ for (ia = (const void *)&a->address, c = 0, i = 0; i < n; i++) {
+ memcpy(&ipa.sin_addr, ia + i*sizeof(ipa.sin_addr),
+ sizeof(ipa.sin_addr));
if (add_ifaddr(p, (struct sockaddr *)&ipa) == LDP_E_OK)
c++;
}
diff -r 5988b4ea4b6b -r 713b0c8b33f6 usr.sbin/ldpd/socketops.c
--- a/usr.sbin/ldpd/socketops.c Sun Jun 26 17:55:24 2022 +0000
+++ b/usr.sbin/ldpd/socketops.c Sun Jun 26 17:55:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.35 2020/04/22 23:53:27 joerg Exp $ */
+/* $NetBSD: socketops.c,v 1.36 2022/06/26 17:55:38 riastradh Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -404,6 +404,7 @@
struct hello_tlv *t;
struct common_hello_tlv *cht;
struct ldp_pdu *spdu;
+ struct in_addr ldp_id;
struct transport_address_tlv *trtlv;
void *v;
struct sockaddr_in sadest; /* Destination ALL_ROUTERS */
@@ -443,7 +444,8 @@
/* Prepare PDU envelope */
spdu->version = htons(LDP_VERSION);
spdu->length = htons(IPV4_HELLO_MSG_SIZE - PDU_VER_LENGTH);
- inet_aton(LDP_ID, &spdu->ldp_id);
+ inet_aton(LDP_ID, &ldp_id);
+ spdu->ldp_id = ldp_id;
/* Prepare Hello TLV */
t->type = htons(LDP_HELLO);
@@ -1387,10 +1389,13 @@
int
send_tlv(const struct ldp_peer * p, const struct tlv * t)
{
+ struct in_addr ldp_id;
struct ldp_pdu pdu;
+ inet_aton(LDP_ID, &ldp_id);
+
pdu.version = htons(LDP_VERSION);
- inet_aton(LDP_ID, &pdu.ldp_id);
+ pdu.ldp_id = ldp_id;
pdu.label_space = 0;
pdu.length = htons(ntohs(t->length) + TLV_TYPE_LENGTH +
PDU_PAYLOAD_LENGTH);
Home |
Main Index |
Thread Index |
Old Index