Use ND_TTEST() rather than comparing against ndo->ndo_snapend ourselves;
it's easy to get the tests wrong.
Check for running out of packet data before checking for running out of
captured data, and distinguish between running out of packet data (which
might just mean "no more strings") and running out of captured data
(which means "truncated").
This fixes a buffer over-read discovered by Forcepoint's security
researchers Otto Airamo & Antti Levomäki.
Add a test using the capture file supplied by the reporter(s).
static char z_buf[256];
static const char *
static char z_buf[256];
static const char *
-parse_field(netdissect_options *ndo, const char **pptr, int *len)
+parse_field(netdissect_options *ndo, const char **pptr, int *len, int *truncated)
- if (*len <= 0 || !pptr || !*pptr)
- return NULL;
- if (*pptr > (const char *) ndo->ndo_snapend)
- return NULL;
-
- while (*pptr <= (const char *) ndo->ndo_snapend && *len >= 0 && **pptr) {
+ /* Scan for the NUL terminator */
+ for (;;) {
+ if (*len == 0) {
+ /* Ran out of packet data without finding it */
+ return NULL;
+ }
+ if (!ND_TTEST(**pptr)) {
+ /* Ran out of captured data without finding it */
+ *truncated = 1;
+ return NULL;
+ }
+ if (**pptr == '\0') {
+ /* Found it */
+ break;
+ }
+ /* Keep scanning */
+ /* Skip the NUL terminator */
- if (*len < 0 || *pptr > (const char *) ndo->ndo_snapend)
- return NULL;
int parselen = length;
const char *s;
int lose = 0;
int parselen = length;
const char *s;
int lose = 0;
/* squelch compiler warnings */
/* squelch compiler warnings */
z.sender = 0;
z.recipient = 0;
z.sender = 0;
z.recipient = 0;
-#define PARSE_STRING \
- s = parse_field(ndo, &parse, &parselen); \
+#define PARSE_STRING \
+ s = parse_field(ndo, &parse, &parselen, &truncated); \
+ if (truncated) goto trunc; \
if (!s) lose = 1;
#define PARSE_FIELD_INT(field) \
if (!s) lose = 1;
#define PARSE_FIELD_INT(field) \
PARSE_FIELD_INT(z.multi);
PARSE_FIELD_STR(z.multi_uid);
PARSE_FIELD_INT(z.multi);
PARSE_FIELD_STR(z.multi_uid);
- if (lose) {
- ND_PRINT((ndo, " [|zephyr] (%d)", length));
- return;
- }
+ if (lose)
+ goto trunc;
ND_PRINT((ndo, " zephyr"));
if (strncmp(z.version+4, "0.2", 3)) {
ND_PRINT((ndo, " zephyr"));
if (strncmp(z.version+4, "0.2", 3)) {
ND_PRINT((ndo, " to %s", z_triple(z.class, z.inst, z.recipient)));
if (*z.opcode)
ND_PRINT((ndo, " op %s", z.opcode));
ND_PRINT((ndo, " to %s", z_triple(z.class, z.inst, z.recipient)));
if (*z.opcode)
ND_PRINT((ndo, " op %s", z.opcode));
+ return;
+
+trunc:
+ ND_PRINT((ndo, " [|zephyr] (%d)", length));
+ return;
tok2str-oobr-1 tok2str-oobr-1.pcap tok2str-oobr-1.out -vvv -e
tok2str-oobr-2 tok2str-oobr-2.pcap tok2str-oobr-2.out -vvv -e
eigrp-tlv-oobr eigrp-tlv-oobr.pcap eigrp-tlv-oobr.out -vvv -e
tok2str-oobr-1 tok2str-oobr-1.pcap tok2str-oobr-1.out -vvv -e
tok2str-oobr-2 tok2str-oobr-2.pcap tok2str-oobr-2.out -vvv -e
eigrp-tlv-oobr eigrp-tlv-oobr.pcap eigrp-tlv-oobr.out -vvv -e
+zephyr-oobr zephyr-oobr.pcap zephyr-oobr.out -vvv -e
# RTP tests
# fuzzed pcap
# RTP tests
# fuzzed pcap
--- /dev/null
+00:16:ca:92:12:01 > 00:15:e8:97:b2:01, ethertype IPv4 (0x0800), length 65535: (tos 0x0, ttl 124, id 16059, offset 0, flags [none], proto UDP (17), length 65521)
+ 167.155.6.190.2104 > 167.155.9.153.514: [udp sum ok]