Have get_uint_value() assume it's being passed an encoding value, which
authorGuy Harris <guy@alum.mit.edu>
Mon, 22 Jul 2013 23:11:07 +0000 (23:11 -0000)
committerGuy Harris <guy@alum.mit.edu>
Mon, 22 Jul 2013 23:11:07 +0000 (23:11 -0000)
isn't necessarily going to be zero if the item is big-endian.

The last argument to test_length() is an encoding, not a big-endian vs.
little-endian Boolean; name it appropriately.

This fixes bug 8953.

svn path=/trunk/; revision=50806

epan/proto.c

index 001cb70f8e9d08e63002c8e2599ea9143be7b06e..1d2541d45250fd56005328c285a3f6b85e5f9e4d 100644 (file)
@@ -1066,12 +1066,6 @@ report_type_length_mismatch(proto_tree *tree, const gchar *descr, int length, gb
        }
 }
 
        }
 }
 
-/*
- * NOTE: to support code written when proto_tree_add_item() took a
- * gboolean as its last argument, with FALSE meaning "big-endian"
- * and TRUE meaning "little-endian", we treat any non-zero value of
- * "encoding" as meaning "little-endian".
- */
 static guint32
 get_uint_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const guint encoding)
 {
 static guint32
 get_uint_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const guint encoding)
 {
@@ -1085,18 +1079,18 @@ get_uint_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const
                break;
 
        case 2:
                break;
 
        case 2:
-               value = encoding ? tvb_get_letohs(tvb, offset)
-                                : tvb_get_ntohs(tvb, offset);
+               value = (encoding & ENC_LITTLE_ENDIAN) ? tvb_get_letohs(tvb, offset)
+                                                      : tvb_get_ntohs(tvb, offset);
                break;
 
        case 3:
                break;
 
        case 3:
-               value = encoding ? tvb_get_letoh24(tvb, offset)
-                                : tvb_get_ntoh24(tvb, offset);
+               value = (encoding & ENC_LITTLE_ENDIAN) ? tvb_get_letoh24(tvb, offset)
+                                                      : tvb_get_ntoh24(tvb, offset);
                break;
 
        case 4:
                break;
 
        case 4:
-               value = encoding ? tvb_get_letohl(tvb, offset)
-                                : tvb_get_ntohl(tvb, offset);
+               value = (encoding & ENC_LITTLE_ENDIAN) ? tvb_get_letohl(tvb, offset)
+                                                      : tvb_get_ntohl(tvb, offset);
                break;
 
        default:
                break;
 
        default:
@@ -1105,8 +1099,8 @@ get_uint_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const
                        value = 0;
                } else {
                        length_error = FALSE;
                        value = 0;
                } else {
                        length_error = FALSE;
-                       value = encoding ? tvb_get_letohl(tvb, offset)
-                                        : tvb_get_ntohl(tvb, offset);
+                       value = (encoding & ENC_LITTLE_ENDIAN) ? tvb_get_letohl(tvb, offset)
+                                                              : tvb_get_ntohl(tvb, offset);
                }
                report_type_length_mismatch(tree, "an unsigned integer", length, length_error);
                break;
                }
                report_type_length_mismatch(tree, "an unsigned integer", length, length_error);
                break;
@@ -1340,7 +1334,7 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree,
                                report_type_length_mismatch(tree, "an IPXNET address", length, length_error);
                        }
                        proto_tree_set_ipxnet(new_fi,
                                report_type_length_mismatch(tree, "an IPXNET address", length, length_error);
                        }
                        proto_tree_set_ipxnet(new_fi,
-                               get_uint_value(tree, tvb, start, FT_IPXNET_LEN, FALSE));
+                               get_uint_value(tree, tvb, start, FT_IPXNET_LEN, ENC_BIG_ENDIAN));
                        break;
 
                case FT_IPv6:
                        break;
 
                case FT_IPv6:
@@ -1777,7 +1771,7 @@ ptvcursor_add(ptvcursor_t *ptvc, int hfindex, gint length,
  */
 static void
 test_length(header_field_info *hfinfo, proto_tree *tree, tvbuff_t *tvb,
  */
 static void
 test_length(header_field_info *hfinfo, proto_tree *tree, tvbuff_t *tvb,
-           gint start, gint length, gboolean little_endian)
+           gint start, gint length, const guint encoding)
 {
        gint size = length;
 
 {
        gint size = length;
 
@@ -1787,7 +1781,7 @@ test_length(header_field_info *hfinfo, proto_tree *tree, tvbuff_t *tvb,
        if (hfinfo->type == FT_UINT_BYTES || hfinfo->type == FT_UINT_STRING) {
                guint32 n;
 
        if (hfinfo->type == FT_UINT_BYTES || hfinfo->type == FT_UINT_STRING) {
                guint32 n;
 
-               n = get_uint_value(tree, tvb, start, length, little_endian);
+               n = get_uint_value(tree, tvb, start, length, encoding);
                if (n > size + n) {
                        /* If n > size + n then we have an integer overflow, so
                         * set size to -1, which will force the
                if (n > size + n) {
                        /* If n > size + n then we have an integer overflow, so
                         * set size to -1, which will force the