aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff_subset.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/tvbuff_subset.c')
-rw-r--r--epan/tvbuff_subset.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/epan/tvbuff_subset.c b/epan/tvbuff_subset.c
index 52a332d878..839facc362 100644
--- a/epan/tvbuff_subset.c
+++ b/epan/tvbuff_subset.c
@@ -172,6 +172,13 @@ tvb_new_subset_length_caplen(tvbuff_t *backing, const gint backing_offset, const
else
actual_reported_length = (guint)reported_length;
+ /*
+ * Cut the captured length short, so it doesn't go past the subset's
+ * reported length.
+ */
+ if (subset_tvb_length > actual_reported_length)
+ subset_tvb_length = actual_reported_length;
+
tvb = tvb_new_with_subset(backing, actual_reported_length,
subset_tvb_offset, subset_tvb_length);
@@ -211,6 +218,16 @@ tvb_new_subset_length(tvbuff_t *backing, const gint backing_offset, const gint r
&subset_tvb_offset,
&subset_tvb_length);
+ /*
+ * If the requested reported length is "to the end of the buffer",
+ * subtract the offset from the total length. We do this now, because
+ * the user might have passed in a negative offset.
+ */
+ if (reported_length == -1) {
+ THROW_ON(backing->reported_length < subset_tvb_offset, ReportedBoundsError);
+ actual_reported_length -= subset_tvb_offset;
+ }
+
tvb = tvb_new_with_subset(backing, (guint)actual_reported_length,
subset_tvb_offset, subset_tvb_length);