Enable ND_LONGJMP_FROM_TCHECK and remove the "trunc" labels.
Use ND_ICHECK_U() for length checks and add standard "invalid" sections.
Remove a ndo_ll_hdr_len increment in a truncation case.
Update chdlc_print() to a void function.
Remove a now useless variable.
Always call ndo->ndo_error with a memory-allocation error if they fail.
Add WARN_UNUSED_RESULT for compilers that support it, and use it for
those routines, so that any future code that doesn't check for failure
gets a warning.
Have nd_push_buffer() take a snapshot length, not a snapshot end, as
its last argument.
Replace nd_push_snapend() and nd_change_snapend() with nd_push_snaplen()
and nd_change_snaplen(), both of which take a pointer into the packet
buffer and snapshot length relative to that pointer as arguments. Have
those routines check the snapshot length to make sure it's not bigger
than the number of bytes in the packet past the pointer, and silently
ignore the requst if it is.
Using a length rather than a pointer avoids the possibility of the
calculation of the snapshot end overflowing and resulting in a snapshot
end *before* the point in the buffer.
Add a test for this, with a capture file containing an IPv6 packet with
an extremely large "jumbo" packet size.
Revert the "Make sure we don't set the snapend before the beginning of
the packet." changes, as they no longer apply with this change (which
also makes sure we don't set the snapend before the beginning of the
packet).
If a caller attempts to set it after the current snapend, just silently
ignore the attempt.
If they try to set it before the beginning of the packet, report it as a
bug and quit dissection. Add a new setjmp() return value meaning "bug"
rather than "truncated packet", add an "nd_bug_longjmp()" routine for
reporting bugs where we should quit dissecting, and use that in this
case.
The Ethertype 0x8899 is used by Realtek for several over-the-wire
protocols, as well as for supplying tag information to a host CPU from a
Realtek chip. Add code to handle protocols other than RRCP, although we
don't fully dissect all of them.
New option `--print-sampling=NTH` will parse and print every NTH packet,
with all other packets producing no output. This option enables
`--print` and `-S` flags.
Print sampling is useful for real-time inspection of an interface with
a high packet rate, or initial inspection of large capture files.
ICHECK like Invalid-Check.
Reminder: If the checked expression is true an error message is printed
and a 'goto invalid' is executed.
This change adds the parameter 'operator'.
Before this change, '<' comparison was hard coded.
We can do now:
ND_ICHECK_U(length, <, HEADER_LEN);
ND_ICHECK_U(length, ==, 24);
ND_ICHECK_U(length, !=, 8);
ND_ICHECK_ZU(length, <, sizeof(struct my_struct));
ND_ICHECKMSG_U("message length", msg_tlen, <, 4);
...
(Any comparison operator)
Remark: The change of names from ND_LCHECK*() to ND_ICHECK*() is
because something else than a length(L) can be checked.
Moreover:
Place the 'message' parameter at the beginning of ND_ICHECKMSG_U()
and ND_ICHECKMSG_ZU() paramaters lists.
...because the former uses PRINTFLIKE_FUNCPTR(). However, it didn't
have the #include. However, the problem was not visible because most
files that included netdissect.h also included (directly or through
another header) funcattrs.h beforehand. The only exceptions were the
following two files, which apparently have not been compiled anywhere
for a long time:
In file included from missing/strdup.c:38:
./netdissect.h:254:8: error: expected ':', ',', ';', '}' or
'__attribute__' before 'PRINTFLIKE_FUNCPTR'
In file included from missing/snprintf.c:45:
./netdissect.h:254:8: error: expected ':', ',', ';', '}' or
'__attribute__' before 'PRINTFLIKE_FUNCPTR'
Add the missing #include to netdissect.h to eliminate this space for
failure.
They check length < minimum for invalid packet with or without a custom
message, format %u or %zu.
%zu (ND_LCHECKMSG_ZU and ND_LCHECK_ZU) is useful when minimum is a
sizeof(...).
[skip ci]
It prints a counted filename (or other ASCII string), part of
the packet buffer, filtering out non-printable characters.
Stop if truncated (via GET_U_1/longjmp) or after n bytes,
whichever is first.
The suffix comes from: j:longJmp, n:after N bytes.
Enable ND_LONGJMP_FROM_TCHECK. Remove many redundant ND_TCHECK*()
instances. Report invalid packets as invalid with a reason, not
truncated. Test whether the invalid packet is entirely in the buffer.
Remove redundant and add plenty of new length checks. Reduce scope for
some variables. Consistently decrement length when advancing the current
pointer. Resort to ND_TCHECK_LEN() only when there are no better ways to
test the packet buffer space.
Do not pass caplen to cdp_print() and remove an improvised snapshot end
guard. Move TLV type-specific code from cdp_print() into standalone
small functions and upgrade a TLV name lookup table into a more
developed TLV registry table along the lines of what was done for
OpenFlow.
In cdp_print_addr() instead of comparing pointers test the address
counter only and trust the loop to do the length checks.
Replace cdp_get_number() with GET_*() macros.
Rewrite the code to make it easier to follow and make indentation more
consistent while at it.
Remove a stray CDP case block from print-chdlc.c.
It prints a null-padded filename (or other ASCII string), part of
the packet buffer, filtering out non-printable characters.
Stop if truncated (via GET_U_1/longjmp) or after n bytes or before
the null char, whichever occurs first.
The suffix comes from: j:longJmp, n:after N bytes, p:null-Padded.
I like the ternary operator (in programming languages that define it with
the same associativity as humans tend to presume), but sometimes a lookup
function is better.
Apply this to the 4 the recently converted protocols.
HOW TO USE:
Define this in a print-*.c file before including netdissect.h to make
all its ND_TCHECK*() instances longjmp(). Only do this after verifying
that every ND_TCHECK*() in the file is correct and that in every
possible case it is safe to call longjmp() without incurring resource
leaks or any other problems. If it is not safe or feasible to convert
whole file, consider converting one function at a time.
Most OpenFlow functions operated on the (cp, ep, len) tuple, returned a
pointer to tell the calling function where to decode next (which was not
a good idea because the calling functions had the values of cp and len in
the first place) and set the pointer to ep to indicate truncated data.
Change them to use the (cp, len) tuple, to be void and to use nd_trunc().
Update the header comment to explain this new convention.
Now if a low-level function gets an offset wrong, as in the bug recently
fixed in of10_queue_props_print(), and manages to return, the error will
not propagate into the calling function, which will be able to continue
the decoding.
Since cp does not have to be current anymore when the [void] function
returns, remove a number of cp increments just before the return.
Introduce OF_FWD(), which modifies both cp and len in sync, and
OF_CHK_FWD(), which also does a bounds check, and use these macros
instead of incrementing cp directly in every function that has both cp
and len arguments. Update the code to account for len that is
decrementing as cp is incrementing.
Commit ad69daa2 was fine for its time, but the introduction of the GET
macros had made it obsolete. Instead of reintroducing ep back merge
of_header_body_print() into openflow_print() to simplify the handling of
pointers, sizes and error conditions, all in the style above.
While at it, subtract OF_HEADER_FIXLEN from the declared OpenFlow message
length before passing it to of10_header_body_print() and make the latter
the only function that has to know about the common header size (clarify
it in the comment). This and the sufficiently current cp and len
disencumber the following functions of type-specific length calculations:
of10_features_reply_print(), of10_flow_mod_print(),
of10_stats_request_print(), of10_stats_reply_print(),
of10_packet_out_print(), of10_packet_in_print() and of10_error_print().
The resulting code in most cases addresses the not yet processed part of
the declared structure with just cp and len: nextfunc(ndo, cp, len) and
ND_TCHECK_LEN(cp, len) do the right thing regardless of how far the
current decoder has made it into the current structure. This makes all
the cp0 and len0 snapshot variables obsolete, so remove them too.
Update a test case output: the missing closing quote now correctly means
that the snapshot end is inside the "data" field of a BSN_SHELL_COMMAND
vendor message, not after it.
Similarly to earlier commits, follow up from commit 19b51ded and make
changes along the same lines. Also make all functions void, lose a few
excess ND_TCHECK_LEN() instances, update comments, reduce scope for a
couple variables, rearrange some line breaks and call ND_TCHECK_LEN()
for unknown protocol versions.
Also rename 'ndo_truncated' to 'ndo_early_end'.
The current case (truncated packet) uses ND_TRUNCATED value.
Prepare to add other cases when the current packet cannot be processed
any more ('Invalid' cases, etc.).
Gisle Vanem reported that GCC 7.1 for DJGPP sees u_int and uint32_t as
two different types, hence the forward declaration for rx_cache_find()
was different from the actual function. UDP port numbers are 16-bit and
udp_print() appropriately uses uint16_t for them. Use the same type in
the downstream Rx-specific code to make things simpler and consistent.
All the link-layer dissectors are now void functions.
All the functions were moved to the void_printers[] array.
Rename this array to printers[].
Remove the uint_printers[] array, now empty.
Remove the 'ndo_void_printer' flag field, now useless, from
netdissect_options.
Remove other transitional code.
It's a follow-up to commit 81dbf4a0b0.
There is no need to update ether_print(), ether_common_print() and
ether_switch_tag_print() to void functions: back to u_int functions.
There is also no need to add a flag parameter to ether_print(),
ether_common_print() and ether_switch_tag_print(): Remove it.
DLT_LANE8023 was never defined in libpcap.
It was, perhaps, defined in some SuSE libpcap update, but no evidence
of this.
It is not defined in OpenSuSE Leap 15.2 (information from Guy).