summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ldpd/labelmapping.c
diff options
context:
space:
mode:
authorrenato <renato@openbsd.org>2016-06-11 01:55:35 +0000
committerrenato <renato@openbsd.org>2016-06-11 01:55:35 +0000
commit2c943183052ed3e41f495abafffa1e7119faa1ab (patch)
treeabdf581a41cf57b77c17d74a60bc65e7bf173c0b /usr.sbin/ldpd/labelmapping.c
parentMake it possible to parse unknown TLVs in the future. (diff)
downloadwireguard-openbsd-2c943183052ed3e41f495abafffa1e7119faa1ab.tar.xz
wireguard-openbsd-2c943183052ed3e41f495abafffa1e7119faa1ab.zip
Make all TLV parsing functions look the same for consistency.
Also, add one more safety check in recv_init().
Diffstat (limited to 'usr.sbin/ldpd/labelmapping.c')
-rw-r--r--usr.sbin/ldpd/labelmapping.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c
index 3aa63d7fd25..48bb19414b4 100644
--- a/usr.sbin/ldpd/labelmapping.c
+++ b/usr.sbin/ldpd/labelmapping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: labelmapping.c,v 1.48 2016/06/11 01:52:33 renato Exp $ */
+/* $OpenBSD: labelmapping.c,v 1.49 2016/06/11 01:55:35 renato Exp $ */
/*
* Copyright (c) 2014, 2015 Renato Westphal <renato@openbsd.org>
@@ -232,6 +232,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
/* Optional Parameters */
while (len > 0) {
struct tlv tlv;
+ uint16_t tlv_len;
uint32_t reqbuf, labelbuf, statusbuf;
if (len < sizeof(tlv)) {
@@ -240,16 +241,17 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
goto err;
}
- memcpy(&tlv, buf, sizeof(tlv));
+ memcpy(&tlv, buf, TLV_HDR_LEN);
buf += TLV_HDR_LEN;
len -= TLV_HDR_LEN;
+ tlv_len = ntohs(tlv.length);
switch (ntohs(tlv.type)) {
case TLV_TYPE_LABELREQUEST:
switch (type) {
case MSG_TYPE_LABELMAPPING:
case MSG_TYPE_LABELREQUEST:
- if (ntohs(tlv.length) != 4) {
+ if (tlv_len != 4) {
session_shutdown(nbr, S_BAD_TLV_LEN,
lm.msgid, lm.type);
goto err;
@@ -272,7 +274,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
switch (type) {
case MSG_TYPE_LABELWITHDRAW:
case MSG_TYPE_LABELRELEASE:
- if (ntohs(tlv.length) != 4) {
+ if (tlv_len != 4) {
session_shutdown(nbr, S_BAD_TLV_LEN,
lm.msgid, lm.type);
goto err;
@@ -304,7 +306,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
case TLV_TYPE_PW_STATUS:
switch (type) {
case MSG_TYPE_LABELMAPPING:
- if (ntohs(tlv.length) != 4) {
+ if (tlv_len != 4) {
session_shutdown(nbr, S_BAD_TLV_LEN,
lm.msgid, lm.type);
goto err;
@@ -327,8 +329,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
/* ignore unknown tlv */
break;
}
- buf += ntohs(tlv.length);
- len -= ntohs(tlv.length);
+ buf += tlv_len;
+ len -= tlv_len;
}
/* notify lde about the received message. */