Tweak/simplify some tvbuff length check functions slightly. In my benchmarks of
dissecting without tree, they are costly because they now happen for every proto_tree_add_item call even if tree is NULL. svn path=/trunk/; revision=52575
This commit is contained in:
parent
3ab8799526
commit
a11b04b5d8
|
@ -149,36 +149,27 @@ tvb_add_to_chain(tvbuff_t *parent, tvbuff_t *child)
|
|||
static inline int
|
||||
validate_offset(const tvbuff_t *tvb, const guint abs_offset)
|
||||
{
|
||||
int exception;
|
||||
|
||||
if (G_LIKELY(abs_offset <= tvb->length))
|
||||
exception = 0;
|
||||
return 0;
|
||||
else if (abs_offset <= tvb->reported_length)
|
||||
exception = BoundsError;
|
||||
else {
|
||||
if (tvb->flags & TVBUFF_FRAGMENT)
|
||||
exception = FragmentBoundsError;
|
||||
return BoundsError;
|
||||
else if (tvb->flags & TVBUFF_FRAGMENT)
|
||||
return FragmentBoundsError;
|
||||
else
|
||||
exception = ReportedBoundsError;
|
||||
}
|
||||
|
||||
return exception;
|
||||
return ReportedBoundsError;
|
||||
}
|
||||
|
||||
static int
|
||||
compute_offset(const tvbuff_t *tvb, const gint offset, guint *offset_ptr)
|
||||
{
|
||||
int exception;
|
||||
|
||||
if (offset >= 0) {
|
||||
/* Positive offset - relative to the beginning of the packet. */
|
||||
if ((guint) offset > tvb->reported_length) {
|
||||
if (tvb->flags & TVBUFF_FRAGMENT) {
|
||||
exception = FragmentBoundsError;
|
||||
return FragmentBoundsError;
|
||||
} else {
|
||||
exception = ReportedBoundsError;
|
||||
return ReportedBoundsError;
|
||||
}
|
||||
return exception;
|
||||
}
|
||||
else if ((guint) offset > tvb->length) {
|
||||
return BoundsError;
|
||||
|
@ -191,11 +182,10 @@ compute_offset(const tvbuff_t *tvb, const gint offset, guint *offset_ptr)
|
|||
/* Negative offset - relative to the end of the packet. */
|
||||
if ((guint) -offset > tvb->reported_length) {
|
||||
if (tvb->flags & TVBUFF_FRAGMENT) {
|
||||
exception = FragmentBoundsError;
|
||||
return FragmentBoundsError;
|
||||
} else {
|
||||
exception = ReportedBoundsError;
|
||||
return ReportedBoundsError;
|
||||
}
|
||||
return exception;
|
||||
}
|
||||
else if ((guint) -offset > tvb->length) {
|
||||
return BoundsError;
|
||||
|
@ -269,11 +259,9 @@ check_offset_length_no_exception(const tvbuff_t *tvb,
|
|||
* Check for an overflow
|
||||
*/
|
||||
if (end_offset < *offset_ptr)
|
||||
exception = BoundsError;
|
||||
else
|
||||
exception = validate_offset(tvb, end_offset);
|
||||
return BoundsError;
|
||||
|
||||
return exception;
|
||||
return validate_offset(tvb, end_offset);
|
||||
}
|
||||
|
||||
/* Checks (+/-) offset and length and throws an exception if
|
||||
|
|
Loading…
Reference in New Issue