Skip to content

Commit 42e67bf

Browse files
committed
VTP: Add a version check
VTP protocol version is 1, 2, or 3. Use nd_print_protocol_caps(). Use ND_ICHECK_U() to replace a custom check.
1 parent 07c3190 commit 42e67bf

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

print-vtp.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,22 @@ vtp_print(netdissect_options *ndo,
121121
u_int type, len, name_len, tlv_len, tlv_value, mgmtd_len;
122122
const u_char *tptr;
123123
const struct vtp_vlan_ *vtp_vlan;
124+
uint8_t version;
124125

125126
ndo->ndo_protocol = "vtp";
126-
if (length < VTP_HEADER_LEN)
127-
goto invalid;
127+
nd_print_protocol_caps(ndo);
128+
ND_ICHECK_U(length, <, VTP_HEADER_LEN);
128129

129130
tptr = pptr;
130131

131132
ND_TCHECK_LEN(tptr, VTP_HEADER_LEN);
132133

134+
version = GET_U_1(tptr);
135+
ND_ICHECK_U(version, <, 1);
136+
ND_ICHECK_U(version, >, 3);
133137
type = GET_U_1(tptr + 1);
134-
ND_PRINT("VTPv%u, Message %s (0x%02x), length %u",
135-
GET_U_1(tptr),
138+
ND_PRINT("v%u, Message %s (0x%02x), length %u",
139+
version,
136140
tok2str(vtp_message_type_values,"Unknown message type", type),
137141
type,
138142
length);

tests/vtp_asan-2.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTPv69, Message Subset advertisement (0x02), length 262131
2-
Domain name: , Seq number: 0, Config Rev fb499603 (invalid) [|vtp]
1+
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTP [version 69 > 3] (invalid) [|vtp]

tests/vtp_asan-3.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTPv69, Message Subset advertisement (0x02), length 262131
2-
Domain name: , Seq number: 0, Config Rev 4040404 (invalid) [|vtp]
1+
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTP [version 69 > 3] (invalid) [|vtp]

tests/vtp_asan.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTPv69, Message Subset advertisement (0x02), length 262131
2-
Domain name: , Seq number: 0 [|vtp]
1+
1 2023-11-18 11:13:40.999999 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTP [version 69 > 3] (invalid) [|vtp]
32
2 [Invalid header: caplen==0]
43
3 [Invalid header: caplen==0, len==0]
54
4 [Invalid header: caplen==0, len==0]

0 commit comments

Comments
 (0)