diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-08-07 20:38:11 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-08-08 03:39:08 +0000 |
commit | 20c0fffc922e09cbb0dbd4317080d3f9ed6a9cae (patch) | |
tree | ec38eb9750ca7d77dbc545bdb738487547022402 /epan/crc32-tvb.c | |
parent | c10396dbbf782a576bc1f9a931cf86090cec3878 (diff) |
Wrap some tvb_get_ptr calls in crc32c_tvb_offset_calculate().
This eliminates some tvb_get_ptr calls from dissectors, as part of
trying to minimize if not eliminate its use in dissectors (it's a bit of
what's called an "attractive nuisance", in that users who don't
understand what it does - and doesn't! - do may use it in ways that are
unsafe, e.g. thinking you can use it to get a null-terminated string
from a packet).
It also eliminates the possibility of passing one length to
tvb_get_ptr() and another to crc32c_calculate().
Change-Id: I8a07168d0bc088b45d607e00c5bb1d98421ebc73
Reviewed-on: https://code.wireshark.org/review/3488
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/crc32-tvb.c')
-rw-r--r-- | epan/crc32-tvb.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/epan/crc32-tvb.c b/epan/crc32-tvb.c index 68b4d119cb..e729ce79cf 100644 --- a/epan/crc32-tvb.c +++ b/epan/crc32-tvb.c @@ -78,6 +78,17 @@ crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, return ( crc32_ccitt_seed(buf, len, seed) ); } +guint32 +crc32c_tvb_offset_calculate(tvbuff_t *tvb, guint offset, guint len, guint32 seed) +{ + const guint8* buf; + + tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, offset, len); + + return ( crc32c_calculate(buf, len, seed) ); +} + /* * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap * the result of "crc32()". |