Commit Graph

87 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
82b4aa217c SNMP: Fix an undefined behavior at runtime
The error was:
print-snmp.c:503:14: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'uint32_t' (aka 'unsigned int')
2019-03-16 13:08:36 +01:00
Francois-Xavier Le Bail
46efa1bc47 Fix spaces 2018-09-03 15:18:19 +02:00
Francois-Xavier Le Bail
ba8936b39b Print truncations with nd_print_trunc() instead of tstr[] strings
Remove the tstr[] strings.
Update the output of some tests accordingly.

Moreover:
Add or update some ndo_protocol fields.
2018-05-04 13:47:49 +02:00
Francois-Xavier Le Bail
3e3e6d2ef4 Rename the fn_printX() functions to nd_printX()
The functions are: nd_print, nd_printztn, nd_printn and nd_printzp.
Trying to make it clearer that they currently have to be used only on part
of the packet buffer.
Update some comments.
2018-04-30 13:35:06 +02:00
Francois-Xavier Le Bail
546558eabd Add the ndo_protocol field in the netdissect_options structure
Update this field in printer entry functions.
It will be used for some printings.
2018-03-16 19:44:47 +01:00
Guy Harris
784b86ec5f Fix bug introduced by previous change.
We aren't post-decrementing the loop index after testing it, we're
decrementing it after the loop body is executed.
2018-02-01 16:06:06 -08:00
Guy Harris
6a42fb7011 Don't decrement an unsigned value past zero.
That also means we do one less decrement, so it's not as if testing
i-- rather than testing i and separately decrementing it is an
optimization.

Fix some types to unsigned while we're at it - and do the above change
for them, too.
2018-02-01 14:25:29 -08:00
Guy Harris
c499612a7f Add nd_{v}snprintf() routines/wrappers.
Some versions of the MSVC runtime library have a non-C99-compliant
vsnprintf(), which we want to avoid.  On Windows, use snprintf() and
vsnprintf() for VS 2015 and later, where they both exist in
C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're
guaranteed to do the null termination that we want).
2018-01-29 15:48:55 -08:00
Guy Harris
fb2479d733 Always include <config.h> rather than "config.h".
This can prevent bizarre failures if, for example, you've done a
configuration in the top-level source directory, leaving behind one
config.h file, and then do an out-of-tree build in another directory,
with different configuration options.  This way, we always pick up the
same config.h, in the build directory.
2018-01-21 12:27:28 -08:00
Francois-Xavier Le Bail
513f782ae1 Use quoted include netdissect-stdinc.h instead of angle-bracketed one 2018-01-21 10:28:15 +01:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
5cea270318 Remove all storage class specifier 'register'
Let the compiler do the optimizations (or not) based on build options.

Avoid 'value has been optimized out' messages in gdb using '-O0'.
2017-12-13 19:17:47 +01:00
Francois-Xavier Le Bail
84ef17ac0e Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)
ND_TTEST2(var, l)  -> ND_TTEST_LEN(p, l)
ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
2017-12-11 22:11:01 +01:00
Francois-Xavier Le Bail
07ac438e08 Use more the EXTRACT_U_1() macro (52/n)
Assignment, p[n]
2017-12-09 14:05:25 +01:00
Francois-Xavier Le Bail
1cfd6cd2ac Use more the EXTRACT_U_1() macro (51/n)
Moreover: Use more the ND_ISPRINT() macro.
2017-12-09 11:46:15 +01:00
Francois-Xavier Le Bail
3a7639e545 Use more the EXTRACT_U_1() macro (49/n)
Assignment, *(p)
2017-12-09 09:56:29 +01:00
Francois-Xavier Le Bail
03a2d9c4c1 Use more the EXTRACT_U_1() macro (47/n)
In: if (... *(p) ...) ...
2017-12-05 10:45:44 +01:00
Francois-Xavier Le Bail
451ac4c753 Use more the ND_TCHECK_1() macro 2017-12-04 21:00:57 +01:00
Francois-Xavier Le Bail
7199dd316f Use more the EXTRACT_U_1() macro (38/n)
In some ND_ISPRINT() macro calls.
2017-12-01 10:27:42 +01:00
Francois-Xavier Le Bail
dde3aa9975 Use more the EXTRACT_U_1() macro (32/n)
In: while (... *(p) ...) ...,
    while (... *(p + e) ...) ...
2017-11-28 22:22:35 +01:00
Francois-Xavier Le Bail
f085c93f59 Use more the EXTRACT_U_1() macro (31/n)
In ND_PRINT() macro call(s) (step 9).

*(p)
2017-11-27 20:57:24 +01:00
Francois-Xavier Le Bail
da20bc56d6 Rename EXTRACT_ macros
Now all the macros have a name meaning a count in bytes.

With _S_: signed, _U_: unsigned

e.g.:
EXTRACT_BE_32BITS -> EXTRACT_BE_U_4
EXTRACT_LE_32BITS -> EXTRACT_LE_U_4
...
EXTRACT_BE_INT32 -> EXTRACT_BE_S_4

and have:
EXTRACT_8BITS -> EXTRACT_U_1
EXTRACT_INT8  -> EXTRACT_S_1
2017-11-22 23:54:09 +01:00
Francois-Xavier Le Bail
c8e0a4a168 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (20/n)
e op *p

Partial list.
2017-11-22 10:36:51 +01:00
Francois-Xavier Le Bail
f7606784db Use more the EXTRACT_8BITS() macro to fetch a one-byte value (16/n)
Assignment, two operators.
((*e1) op1 e2) op2 e3
2017-11-21 19:30:53 +01:00
Francois-Xavier Le Bail
4b21d2bad7 Use more the EXTRACT_8BITS() macro to fetch a one-byte value (14/n)
Assignment, one operator.
2017-11-21 17:38:35 +01:00
Denis Ovsienko
eec1624f7b CVE-2017-5483/SNMP: improve ASN.1 bounds checks
Kamil Frankowicz had found that truncated BE_STR and BE_SEQ ASN.1
elements could lead to an overread, from the source code it looked like
other ids could have this problem too. Move the checks introduced in
commit 72e501f out of the switch blocks to cover all ids by default.
This fixes GH#559 and GH#566.
2017-01-18 09:16:41 +01:00
Guy Harris
67b7b0a0e8 Clean up the "have libsmi but no modules loaded" case.
Have asn1_print() print out OIDs regardless of whether we have any
modules loaded or not.

Have smi_decode_oid decode the OID to an array of unsigned ints
regardless of whether we have any modules loaded or not.

Have smi_print_variable() just use asn1_print() to print the OID of a
variable binding if we don't have any modules loaded; in that case,
we're not going to try to look the OID up with libsmi, so we don't need
a decoded version.

Have smi_print_value() not bother decoding the OID or looking the OID up
if we don't have any modules loaded; also, if we *do* have modules
loaded, check whether smi_decode_oid() succeeds.
2017-01-18 09:16:41 +01:00
Guy Harris
410956bc36 Clean up the object abbreviation list.
Have the OID prefixes be arrays of uint8_t, and put the size of the
array into the list, rather than having them be "strings" and et the
length with strlen().

Have a macro to encapsulate X.690 section 8.19.4's rules for the first
octet of an OID value, and use it; that makes the components of the OID
clearer.

Also, if the prefix is longer than the remaining data in the OID - or
the remaining captured data - just skip it, don't treat that as an
error.
2017-01-18 09:16:40 +01:00
Guy Harris
0cb34b7b44 Just handle COUNTER64 as a u_int64.
No need to worry about 64-bit integers any more - we require compiler
and printf support for them.
2017-01-18 09:16:40 +01:00
Guy Harris
e4371fa1e8 More bounds and length checks.
Catch INTEGER values with a length of 0, so we don't fetch a byte that
doesn't belong to the value.

Fix what appears to be a long-standing bug in the OID prefix matching
code, wherein the length of the *first* prefix in the table is used as
the length of *all* prefixes, and add some packet-length checking to
that list.

Report packets with an invalid SNMP version number as being SNMP, so
we at least indicate *that*.
2017-01-18 09:16:40 +01:00
Francois-Xavier Le Bail
79d80f09f3 SNMP: Add some bounds checks 2017-01-18 09:16:40 +01:00
Guy Harris
9f8c1a7492 Do bounds checks when printing character and octet strings.
Pull the code in asn1_print() to print octet sequences and (presumed)
printable strings into routines of their own, and use them when we're
printing them outside asn1_print().

That fixes some cases where we can run past the end of the packet
buffer.
2017-01-18 09:16:40 +01:00
Francois-Xavier Le Bail
ca54d72376 Declare some variables as static 2016-09-11 21:45:26 +02:00
Francois-Xavier Le Bail
11d3a01319 Move the printer summaries from INSTALL.txt to each printer
with the tag '\summary:' for greping.
Remark: Currently some printers have no summary line.

Moreover:
Summarize all printers with a single line in INSTALL.txt
2016-08-14 17:03:43 +02:00
Guy Harris
6080cff326 Move more libsmi stuff to netdissect.c.
Have the call to smiLoadModule() be in a nd_load_smi_module() routine.
Have it set a *global* flag indicating whether a module has been loaded;
that's not per-netdissect_options.  Use that global flag in print-snmp.c
- and don't test it once per loop iteration, it's not going to change
while the loop is running.

Have a routine to return the version of the library if we're built with
it or NULL if we're not.

That removes the last of the code that tests USE_LIBSMI or uses libsmi
from tcpdump.c.
2016-08-04 14:35:35 -07:00
Guy Harris
2be6e0e953 Make pduid a u_short consistently. 2015-09-14 15:04:12 -07:00
Francois-Xavier Le Bail
99c91c3aec Rename 'tcpdump-stdinc.h' to 'netdissect-stdinc.h'
Get the full log via: git log --follow netdissect-stdinc.h
2015-09-10 08:50:40 +02:00
Francois-Xavier Le Bail
a306c9e7be Update a ndo flag name
Even if frontend/backend separation is ongoing, keep coherence between
option name and flag name at the moment.
Option name is 'm', thus s/ndo_sflag/ndo_mflag/.
2015-09-09 13:32:20 +02:00
Francois-Xavier Le Bail
c1c3c77463 Printers must include 'netdissect.h', not 'interface.h' 2015-09-05 23:35:58 +02:00
Guy Harris
486704db7c Avoid collison with error(), clean up code a bit.
Rename the variable to "error_status", as that's what it represents, and
as that doesn't collide with the error() function.  Don't set it and
then not use the resulting value.
2015-08-31 16:57:07 -07:00
Francois-Xavier Le Bail
b1c65c20a7 Fix warnings as "declaration of 'x' shadows a previous local" 2015-07-12 20:32:35 +02:00
Guy Harris
69cb46af91 Fix a bunch of de-constifications. 2015-04-26 17:24:42 -07:00
Denis Ovsienko
38700c7f24 dismiss NETDISSECT_REWORKED macro
The purpose of this macro was to enable the file-by-file switch to NDO,
after which only tcpdump.c had a use of it and the definitions guarded
by it. Update tcpdump.c not to require them any more and dismiss the
unused definitions.
2015-03-22 10:06:15 +00:00
Guy Harris
37a4aa82a9 Clean up configure check for libsmi.
First, check for smi.h.  If we don't have it, don't check for anything
else.

If we do have it, check for libsmi containing smiInit.  If we don't have
it, don't check for anything else.

If we do have it, check, with our test program, whether we can use it.

If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI.  Otherwise,
don't do either of those.

Check, in source, *only* for USE_LIBSMI.  If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-08-31 11:57:04 -07:00
Guy Harris
572d63471c Clean up the first-item handling a bit.
This makes it look a bit more like the handling of other items.
2014-07-08 03:26:18 -07:00
Guy Harris
b6a3595a55 Squelch a Coverity warning.
If you pass in a value of oidlen and oidsize such that we can't store
*anything* into OID, this would be a problem; that *shouldn't* ever
happen, but this makes the code a bit more obviously correct.
2014-07-08 03:23:09 -07:00
Guy Harris
ed85e20e4d u_intN_t is dead, long live uintN_t.
And, as we require at least autoconf 2.61, and as autoconf 2.61 and
later have AC_TYPE_UINTn_T and AC_TYPE_INTn_T macros, we use them to
define the uintN_t and intN_t macros if the system doesn't define them
for us.

This lets us get rid of bitypes.h as well.
2014-04-23 00:20:40 -07:00
Denis Ovsienko
24598ce6b7 NDOize the rest of util.c 2014-04-14 10:53:46 +04:00
Denis Ovsienko
0015471d7d amend previous commit to fix compiling with libsmi 2014-03-30 10:48:43 +04:00
Denis Ovsienko
157d13fe56 NDOize SNMP decoder 2014-03-29 15:39:31 +04:00