summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/rde_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bgpd/rde_attr.c')
-rw-r--r--usr.sbin/bgpd/rde_attr.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c
index b1b4957475b..2d67efa829a 100644
--- a/usr.sbin/bgpd/rde_attr.c
+++ b/usr.sbin/bgpd/rde_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_attr.c,v 1.134 2023/07/12 14:45:43 claudio Exp $ */
+/* $OpenBSD: rde_attr.c,v 1.135 2024/09/10 09:38:45 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -357,7 +357,8 @@ aspath_get(void *data, uint16_t len)
aspath->len = len;
aspath->ascnt = aspath_count(data, len);
aspath->source_as = aspath_extract_origin(data, len);
- memcpy(aspath->data, data, len);
+ if (len != 0)
+ memcpy(aspath->data, data, len);
return (aspath);
}
@@ -396,7 +397,7 @@ aspath_put(struct aspath *aspath)
u_char *
aspath_deflate(u_char *data, uint16_t *len, int *flagnew)
{
- uint8_t *seg, *nseg, *ndata;
+ uint8_t *seg, *nseg, *ndata = NULL;
uint32_t as;
int i;
uint16_t seg_size, olen, nlen;
@@ -415,6 +416,9 @@ aspath_deflate(u_char *data, uint16_t *len, int *flagnew)
fatalx("%s: would overflow", __func__);
}
+ if (nlen == 0)
+ goto done;
+
if ((ndata = malloc(nlen)) == NULL)
fatal("%s", __func__);
@@ -437,6 +441,7 @@ aspath_deflate(u_char *data, uint16_t *len, int *flagnew)
}
}
+ done:
*len = nlen;
return (ndata);
}
@@ -791,6 +796,10 @@ aspath_prepend(struct aspath *asp, uint32_t as, int quantum, uint16_t *len)
fatalx("aspath_prepend: preposterous prepend");
if (quantum == 0) {
/* no change needed but return a copy */
+ if (asp->len == 0) {
+ *len = 0;
+ return (NULL);
+ }
p = malloc(asp->len);
if (p == NULL)
fatal("%s", __func__);
@@ -834,7 +843,8 @@ aspath_prepend(struct aspath *asp, uint32_t as, int quantum, uint16_t *len)
wpos += sizeof(uint32_t);
}
}
- memcpy(p + wpos, asp->data + shift, asp->len - shift);
+ if (asp->len > shift)
+ memcpy(p + wpos, asp->data + shift, asp->len - shift);
*len = l;
return (p);
@@ -852,6 +862,11 @@ aspath_override(struct aspath *asp, uint32_t neighbor_as, uint32_t local_as,
uint16_t l, seg_size;
uint8_t i, seg_len, seg_type;
+ if (asp->len == 0) {
+ *len = 0;
+ return (NULL);
+ }
+
p = malloc(asp->len);
if (p == NULL)
fatal("%s", __func__);