aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/file-elf.c
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss.ws@gmail.com>2013-10-25 14:04:22 +0000
committerJeff Morriss <jeff.morriss.ws@gmail.com>2013-10-25 14:04:22 +0000
commitab97b9d50b9f3da6677470514df5f91c752541c6 (patch)
tree9ce053e909a43ef336b089cc3ff9a769220fa690 /epan/dissectors/file-elf.c
parent02784747f72804558f84cacaa71749eedbd912e7 (diff)
Fix CID 1111806: it's not safe to check if "tag < sizeof(tag_to_type)" before
accessing tag_to_type[tag]: while the array is made of enums and the values of the enum will fit in a guint8 (making the conditional safe) compilers don't *have* to "right size" the storage for the enum. They very well could be lazy and store the enum in int's. Replace it with a macro that tells us the size of the array. svn path=/trunk/; revision=52842
Diffstat (limited to 'epan/dissectors/file-elf.c')
-rw-r--r--epan/dissectors/file-elf.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/epan/dissectors/file-elf.c b/epan/dissectors/file-elf.c
index 31069c1ab1..d9108b6f0e 100644
--- a/epan/dissectors/file-elf.c
+++ b/epan/dissectors/file-elf.c
@@ -656,6 +656,7 @@ get_section_name_offset(tvbuff_t *tvb, guint64 shoff, guint16 shnum, guint16 she
return tvb_get_const_stringz(tvb, value_guard(shstrtab_offset + sh_name), NULL);
}
+#define MAX_TAG_TO_TYPE 34
static gint
dissect_dynamic(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *entry_tree, proto_item *entry_item,
gint offset, gint register_size, guint machine_encoding)
@@ -668,7 +669,7 @@ dissect_dynamic(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *entry_tree, p
};
guint64 tag;
- static const enum enum_tag_type tag_to_type[34] = {
+ static const enum enum_tag_type tag_to_type[MAX_TAG_TO_TYPE] = {
DYNAMIC_TYPE_IGNORED,
DYNAMIC_TYPE_VALUE,
DYNAMIC_TYPE_VALUE,
@@ -710,11 +711,11 @@ dissect_dynamic(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *entry_tree, p
tag = (machine_encoding == ENC_BIG_ENDIAN) ? tvb_get_ntohl(tvb, offset) : tvb_get_letohl(tvb, offset);
offset += 4;
- if (tag < sizeof(tag_to_type) && tag_to_type[tag] == DYNAMIC_TYPE_VALUE)
+ if (tag < MAX_TAG_TO_TYPE && tag_to_type[tag] == DYNAMIC_TYPE_VALUE)
proto_tree_add_item(entry_tree, hf_elf_dynamic_value, tvb, offset, 4, machine_encoding);
- else if (tag < sizeof(tag_to_type) && tag_to_type[tag] == DYNAMIC_TYPE_POINTER)
+ else if (tag < MAX_TAG_TO_TYPE && tag_to_type[tag] == DYNAMIC_TYPE_POINTER)
proto_tree_add_item(entry_tree, hf_elf_dynamic_pointer, tvb, offset, 4, machine_encoding);
- else if (tag < sizeof(tag_to_type) && tag_to_type[tag] == DYNAMIC_TYPE_IGNORED)
+ else if (tag < MAX_TAG_TO_TYPE && tag_to_type[tag] == DYNAMIC_TYPE_IGNORED)
proto_tree_add_item(entry_tree, hf_elf_dynamic_ignored, tvb, offset, 4, machine_encoding);
else
proto_tree_add_item(entry_tree, hf_elf_dynamic_unspecified, tvb, offset, 4, machine_encoding);