aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-tvbuff.c
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2010-08-08 19:04:35 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2010-08-08 19:04:35 +0000
commitfcc9f7a569a45d9d06c8d067d9749cdea8a0f4d9 (patch)
tree667ca21b88ef6f8dc18eee64bb036dd2871f318f /epan/ftypes/ftype-tvbuff.c
parentd7e5218d7a1d3f314fbf21c23d1f355dbecc9d66 (diff)
Protect tvb_* functions in a TRY-CATCH block.
This fixes bug 5087. svn path=/trunk/; revision=33735
Diffstat (limited to 'epan/ftypes/ftype-tvbuff.c')
-rw-r--r--epan/ftypes/ftype-tvbuff.c214
1 files changed, 150 insertions, 64 deletions
diff --git a/epan/ftypes/ftype-tvbuff.c b/epan/ftypes/ftype-tvbuff.c
index 4d18388274..2b1b44373f 100644
--- a/epan/ftypes/ftype-tvbuff.c
+++ b/epan/ftypes/ftype-tvbuff.c
@@ -134,10 +134,19 @@ val_repr_len(fvalue_t *fv, ftrepr_t rtype)
guint length;
if (rtype != FTREPR_DFILTER) return -1;
- length = tvb_length(fv->value.tvb);
- /* 3 bytes for each byte of the byte "NN:" minus 1 byte
- * as there's no trailing ":". */
- return length * 3 - 1;
+
+ TRY {
+ length = tvb_length(fv->value.tvb);
+ /* 3 bytes for each byte of the byte "NN:" minus 1 byte
+ * as there's no trailing ":". */
+ return length * 3 - 1;
+ }
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
+
+ return 0;
}
static void
@@ -149,20 +158,27 @@ val_to_repr(fvalue_t *fv, ftrepr_t rtype, char *buf)
unsigned int i;
g_assert(rtype == FTREPR_DFILTER);
- length = tvb_length(fv->value.tvb);
- c = tvb_get_ptr(fv->value.tvb, 0, length);
- write_cursor = buf;
-
- for (i = 0; i < length; i++) {
- if (i == 0) {
- sprintf(write_cursor, "%02x", *c++);
- write_cursor += 2;
- }
- else {
- sprintf(write_cursor, ":%02x", *c++);
- write_cursor += 3;
+
+ TRY {
+ length = tvb_length(fv->value.tvb);
+ c = tvb_get_ptr(fv->value.tvb, 0, length);
+ write_cursor = buf;
+
+ for (i = 0; i < length; i++) {
+ if (i == 0) {
+ sprintf(write_cursor, "%02x", *c++);
+ write_cursor += 2;
+ }
+ else {
+ sprintf(write_cursor, ":%02x", *c++);
+ write_cursor += 3;
+ }
}
}
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
}
static gpointer
@@ -174,10 +190,18 @@ value_get(fvalue_t *fv)
static guint
len(fvalue_t *fv)
{
- if (fv->value.tvb)
- return tvb_length(fv->value.tvb);
- else
- return 0;
+ TRY {
+ if (fv->value.tvb)
+ return tvb_length(fv->value.tvb);
+ else
+ return 0;
+ }
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
+
+ return 0;
}
static void
@@ -203,13 +227,22 @@ cmp_eq(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- if (a_len != tvb_length(b)) {
- return FALSE;
+ TRY {
+ guint a_len = tvb_length(a);
+
+ if (a_len != tvb_length(b)) {
+ return FALSE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) == 0);
+ }
+ CATCH_ALL {
+ /* nothing */
}
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) == 0);
+ return FALSE;
}
static gboolean
@@ -217,13 +250,22 @@ cmp_ne(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- if (a_len != tvb_length(b)) {
- return TRUE;
+ TRY {
+ guint a_len = tvb_length(a);
+
+ if (a_len != tvb_length(b)) {
+ return TRUE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) != 0);
+ }
+ CATCH_ALL {
+ /* nothing */
}
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) != 0);
+ return FALSE;
}
static gboolean
@@ -231,18 +273,27 @@ cmp_gt(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- guint b_len = tvb_length(b);
- if (a_len > b_len) {
- return TRUE;
- }
+ TRY {
+ guint a_len = tvb_length(a);
+ guint b_len = tvb_length(b);
+
+ if (a_len > b_len) {
+ return TRUE;
+ }
- if (a_len < b_len) {
- return FALSE;
+ if (a_len < b_len) {
+ return FALSE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) > 0);
+ }
+ CATCH_ALL {
+ /* nothing */
}
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) > 0);
+ return FALSE;
}
static gboolean
@@ -250,18 +301,27 @@ cmp_ge(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- guint b_len = tvb_length(b);
+
+ TRY {
+ guint a_len = tvb_length(a);
+ guint b_len = tvb_length(b);
- if (a_len > b_len) {
- return TRUE;
- }
+ if (a_len > b_len) {
+ return TRUE;
+ }
- if (a_len < b_len) {
- return FALSE;
+ if (a_len < b_len) {
+ return FALSE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) >= 0);
}
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) >= 0);
+ return FALSE;
}
static gboolean
@@ -269,18 +329,27 @@ cmp_lt(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- guint b_len = tvb_length(b);
- if (a_len < b_len) {
- return TRUE;
- }
+ TRY {
+ guint a_len = tvb_length(a);
+ guint b_len = tvb_length(b);
+
+ if (a_len < b_len) {
+ return TRUE;
+ }
- if (a_len > b_len) {
- return FALSE;
+ if (a_len > b_len) {
+ return FALSE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) < 0);
}
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) < 0);
+ return FALSE;
}
static gboolean
@@ -288,29 +357,46 @@ cmp_le(fvalue_t *fv_a, fvalue_t *fv_b)
{
tvbuff_t *a = fv_a->value.tvb;
tvbuff_t *b = fv_b->value.tvb;
- guint a_len = tvb_length(a);
- guint b_len = tvb_length(b);
- if (a_len < b_len) {
- return TRUE;
- }
+ TRY {
+ guint a_len = tvb_length(a);
+ guint b_len = tvb_length(b);
- if (a_len > b_len) {
- return FALSE;
+ if (a_len < b_len) {
+ return TRUE;
+ }
+
+ if (a_len > b_len) {
+ return FALSE;
+ }
+
+ return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) <= 0);
}
+ CATCH_ALL {
+ /* nothing */
+ }
+ ENDTRY;
- return (memcmp(tvb_get_ptr(a, 0, a_len), tvb_get_ptr(b, 0, a_len), a_len) <= 0);
+ return FALSE;
}
static gboolean
cmp_contains(fvalue_t *fv_a, fvalue_t *fv_b)
{
- if (tvb_find_tvb(fv_a->value.tvb, fv_b->value.tvb, 0) > -1) {
- return TRUE;
+ TRY {
+ if (tvb_find_tvb(fv_a->value.tvb, fv_b->value.tvb, 0) > -1) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
}
- else {
- return FALSE;
+ CATCH_ALL {
+ /* nothing */
}
+ ENDTRY;
+
+ return FALSE;
}
#ifdef HAVE_LIBPCRE