aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-06-15 13:32:46 -0700
committerGuy Harris <gharris@sonic.net>2021-06-15 13:32:46 -0700
commite5ce3345db9e370e50bc69d19b928e42b4ddd61f (patch)
tree1ad1c87d1adf61c144b3ff46733af47528720205 /epan/tvbuff.c
parent2c6d897b5882c942b8615651aae7aab47aa462fd (diff)
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.)
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index b154791a4d..d737fad84f 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -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