tvbuff: add tvb_ensure_reported_length_remaining().
It is to tvb_reported_length_remaining() as tvb_ensure_captured_length_remaining() is to tvb_captured_length_remaining() - it throws an exception if the offset is out of range. (Note that an offset that's just past the end of the {reported, captured} data is *not* out of range, it just means that there is no data remaining. Anything *past* that is out of range and thus invalid.)
This commit is contained in:
parent
2c6d897b58
commit
e5ce3345db
|
@ -1730,6 +1730,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
|
|||
tvb_ensure_bytes_exist@Base 1.9.1
|
||||
tvb_ensure_bytes_exist64@Base 1.99.0
|
||||
tvb_ensure_captured_length_remaining@Base 1.12.0~rc1
|
||||
tvb_ensure_reported_length_remaining@Base 3.5.0
|
||||
tvb_get_etsi_ts_102_221_annex_a_string@Base 3.3.1
|
||||
tvb_find_guint8@Base 1.9.1
|
||||
tvb_find_guint16@Base 2.3.0
|
||||
|
|
|
@ -539,9 +539,6 @@ tvb_ensure_captured_length_remaining(const tvbuff_t *tvb, const gint offset)
|
|||
return rem_length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Validates that 'length' bytes are available starting from
|
||||
* offset (pos/neg). Does not throw an exception. */
|
||||
gboolean
|
||||
|
@ -713,6 +710,24 @@ tvb_reported_length_remaining(const tvbuff_t *tvb, const gint offset)
|
|||
return 0;
|
||||
}
|
||||
|
||||
guint
|
||||
tvb_ensure_reported_length_remaining(const tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint abs_offset = 0;
|
||||
int exception;
|
||||
|
||||
DISSECTOR_ASSERT(tvb && tvb->initialized);
|
||||
|
||||
exception = compute_offset(tvb, offset, &abs_offset);
|
||||
if (exception)
|
||||
THROW(exception);
|
||||
|
||||
if (tvb->reported_length >= abs_offset)
|
||||
return tvb->reported_length - abs_offset;
|
||||
else
|
||||
THROW(ReportedBoundsError);
|
||||
}
|
||||
|
||||
/* Set the reported length of a tvbuff to a given value; used for protocols
|
||||
* whose headers contain an explicit length and where the calling
|
||||
* dissector's payload may include padding as well as the packet for
|
||||
|
|
|
@ -252,6 +252,10 @@ WS_DLL_PUBLIC guint tvb_reported_length(const tvbuff_t *tvb);
|
|||
WS_DLL_PUBLIC gint tvb_reported_length_remaining(const tvbuff_t *tvb,
|
||||
const gint offset);
|
||||
|
||||
/** Same as above, but throws an exception if the offset is out of bounds. */
|
||||
WS_DLL_PUBLIC guint tvb_ensure_reported_length_remaining(const tvbuff_t *tvb,
|
||||
const gint offset);
|
||||
|
||||
/** Set the reported length of a tvbuff to a given value; used for protocols
|
||||
whose headers contain an explicit length and where the calling
|
||||
dissector's payload may include padding as well as the packet for
|
||||
|
|
Loading…
Reference in New Issue