aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2017-05-06 19:34:24 +0200
committerMartin Kaiser <wireshark@kaiser.cx>2017-05-07 18:18:26 +0000
commitd0e317d69e07412a330d1d67038ac4194caf55eb (patch)
tree164d87a1c8b8a4ab4bf66503d60e670ff3d6608c
parent8657646e0b2ee68de0defa1f9d9fd7ed23ba126f (diff)
gif: refactor the detection of a gif file
Generally, we should not throw an exception before we know that this is our file/packet. Use tvb_strneql() to get the version string. This function does not throw an exception if there are fewer bytes left than we requested. (I know that we check for reported len < 20. However, for captured length > 6 and reported length < 20, the current code does not work.) Change-Id: I5214c5c9dc9da616a94ae96269ec1c9e6f412e8e Reviewed-on: https://code.wireshark.org/review/21544 Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
-rw-r--r--epan/dissectors/file-gif.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/epan/dissectors/file-gif.c b/epan/dissectors/file-gif.c
index 1fd748d3cc..0189311b29 100644
--- a/epan/dissectors/file-gif.c
+++ b/epan/dissectors/file-gif.c
@@ -308,29 +308,27 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
guint8 color_resolution;
guint8 image_bpp;
guint tvb_len = tvb_reported_length(tvb);
- char *str;
-
- guint8 version = 0;
+ char *ver_str;
+ guint8 version;
if (tvb_len < 20)
return 0;
- str = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, 6, ENC_ASCII|ENC_NA);
/* Check whether we're processing a GIF object */
/* see http://www.w3.org/Graphics/GIF/spec-gif89a.txt section 17 */
- if (strcmp(str, "GIF87a") == 0) {
+ if (!tvb_strneql(tvb, 0, "GIF87a", 6) == 0) {
version = GIF_87a;
- } else if (strcmp(str, "GIF89a") == 0) {
+ } else if (!tvb_strneql(tvb, 0, "GIF89a", 6) == 0) {
version = GIF_89a;
} else {
/* Not a GIF image! */
return 0;
}
- DISSECTOR_ASSERT(version);
+ ver_str = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, 6, ENC_ASCII|ENC_NA);
/* Add summary to INFO column if it is enabled */
- col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", str);
+ col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", ver_str);
/* In order to speed up dissection, do not add items to the protocol tree
* if it is not visible. However, compute the values that are needed for
@@ -339,7 +337,7 @@ dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
*/
if (tree) {
ti = proto_tree_add_item(tree, hfi_gif, tvb, 0, -1, ENC_NA);
- proto_item_append_text(ti, ", Version: %s", str);
+ proto_item_append_text(ti, ", Version: %s", ver_str);
gif_tree = proto_item_add_subtree(ti, ett_gif);
/* GIF signature */
proto_tree_add_item(gif_tree, &hfi_version, tvb, 0, 6, ENC_ASCII|ENC_NA);