Skip to content

Commit 9aee996

Browse files
committed
ESP: Delete a useless custom bounds check
The two GET_BE_U_4() perform the bounds checks. Print the protocol name, with nd_print_protocol_caps(), before any check. Add a test file with a truncated ESP packet.
1 parent 6cd500c commit 9aee996

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

print-esp.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ esp_print(netdissect_options *ndo,
747747
u_int ttl_hl USED_IF_LIBCRYPTO)
748748
{
749749
const struct newesp *esp;
750-
const u_char *ep;
751750
#ifdef HAVE_LIBCRYPTO
751+
const u_char *ep;
752752
const struct ip *ip;
753753
struct sa_list *sa = NULL;
754754
const struct ip6_hdr *ip6 = NULL;
@@ -764,18 +764,16 @@ esp_print(netdissect_options *ndo,
764764
ndo->ndo_protocol = "esp";
765765
esp = (const struct newesp *)bp;
766766

767-
/* 'ep' points to the end of available data. */
768-
ep = ndo->ndo_snapend;
767+
nd_print_protocol_caps(ndo);
769768

770-
if ((const u_char *)(esp + 1) >= ep) {
771-
nd_print_trunc(ndo);
772-
return;
773-
}
774-
ND_PRINT("ESP(spi=0x%08x", GET_BE_U_4(esp->esp_spi));
769+
ND_PRINT("(spi=0x%08x", GET_BE_U_4(esp->esp_spi));
775770
ND_PRINT(",seq=0x%x)", GET_BE_U_4(esp->esp_seq));
776771
ND_PRINT(", length %u", length);
777772

778773
#ifdef HAVE_LIBCRYPTO
774+
/* 'ep' points to the end of available data. */
775+
ep = ndo->ndo_snapend;
776+
779777
/* initialize SAs */
780778
if (ndo->ndo_sa_list_head == NULL) {
781779
if (!ndo->ndo_espsecret)

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ edsa-high-vid-e edsa-high-vid.pcap edsa-high-vid-e.out -e
110110

111111
# ESP tests
112112
esp0 02-sunrise-sunset-esp.pcap esp0.out
113+
esp_truncated esp_truncated.pcap esp_truncated.out
113114
# more ESP tests in crypto.tests
114115

115116
# ISAKMP tests

tests/esp_truncated.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2020-11-19 12:07:26.999999 IP 0.254.92.182.4500 > 255.127.255.121.8472: UDP-encap: ESP(spi=0xc0f7d4c3 [|esp]

tests/esp_truncated.pcap

86 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)