diff options
author | Guy Harris <guy@alum.mit.edu> | 2007-03-25 21:07:24 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2007-03-25 21:07:24 +0000 |
commit | 79561053bb22c9b7538b7035a55d2248736f74b6 (patch) | |
tree | b86bb696b0d0ac56c0a47f50aa5335a3e57dd39c /epan/dissectors/packet-mpeg-audio.c | |
parent | 4e7a4e0b06525ec0b61d49c0a96e265863a8217f (diff) |
Before we've decided to dissect a frame, don't fetch any data before
checking to make sure it's available.
Don't dissect an audio frame if it doesn't have a valid version or layer
value.
Don't do anything with the columns until we've decided to accept a
frame.
The register routines are only called once; we don't have to check
whether they've already been called.
svn path=/trunk/; revision=21186
Diffstat (limited to 'epan/dissectors/packet-mpeg-audio.c')
-rw-r--r-- | epan/dissectors/packet-mpeg-audio.c | 94 |
1 files changed, 43 insertions, 51 deletions
diff --git a/epan/dissectors/packet-mpeg-audio.c b/epan/dissectors/packet-mpeg-audio.c index b3cc73b3f8..202a74f643 100644 --- a/epan/dissectors/packet-mpeg-audio.c +++ b/epan/dissectors/packet-mpeg-audio.c @@ -454,60 +454,56 @@ dissect_mpeg_audio_ID3v1(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_ /*--- End of included file: packet-mpeg-audio-fn.c ---*/ #line 44 "packet-mpeg-audio-template.c" +static int proto_mpeg_audio = -1; + static int hf_mpeg_audio = -1; static int hf_mpeg_audio_data = -1; static int hf_mpeg_audio_padbytes = -1; static int hf_id3v1 = -1; static int hf_id3v2 = -1; -static size_t -read_header(tvbuff_t *tvb, packet_info *pinfo, struct mpa *mpa) -{ - size_t data_size = 0; - guint32 h = tvb_get_ntohl(tvb, 0); - MPA_UNMARSHAL(mpa, h); - if (MPA_SYNC_VALID(mpa)) { - if (MPA_VERSION_VALID(mpa) && MPA_LAYER_VALID(mpa)) { - if (check_col(pinfo->cinfo, COL_PROTOCOL)) { - static const char *version_names[] = { "1", "2", "2.5" }; - col_add_fstr(pinfo->cinfo, COL_PROTOCOL, - "MPEG-%s", version_names[MPA_VERSION(mpa)]); - } - if (check_col(pinfo->cinfo, COL_INFO)) - col_add_fstr(pinfo->cinfo, COL_INFO, - "Audio Layer %d", MPA_LAYER(mpa) + 1); - if (MPA_BITRATE_VALID(mpa) && MPA_FREQUENCY_VALID(mpa)) { - data_size = MPA_DATA_BYTES(mpa) - sizeof mpa; - if (check_col(pinfo->cinfo, COL_DEF_SRC)) { - SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL); - col_add_fstr(pinfo->cinfo, COL_DEF_SRC, - "%d kb/s", MPA_BITRATE(mpa) / 1000); - } - if (check_col(pinfo->cinfo, COL_DEF_DST)) { - SET_ADDRESS(&pinfo->dst, AT_NONE, 0, NULL); - col_add_fstr(pinfo->cinfo, COL_DEF_DST, - "%g kHz", MPA_FREQUENCY(mpa) / (float)1000); - } - } - } else { - if (check_col(pinfo->cinfo, COL_PROTOCOL)) - col_add_str(pinfo->cinfo, COL_PROTOCOL, "MPEG"); - } - } - return data_size; -} - static gboolean dissect_mpeg_audio_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + guint32 h; struct mpa mpa; - size_t data_size; + size_t data_size = 0; asn1_ctx_t asn1_ctx; int offset = 0; - data_size = read_header(tvb, pinfo, &mpa); + if (!tvb_bytes_exist(tvb, 0, 4)) + return FALSE; /* not enough data for an MPEG audio frame */ + + h = tvb_get_ntohl(tvb, 0); + MPA_UNMARSHAL(&mpa, h); if (!MPA_SYNC_VALID(&mpa)) return FALSE; + if (!MPA_VERSION_VALID(&mpa)) + return FALSE; + if (!MPA_LAYER_VALID(&mpa)) + return FALSE; + + if (check_col(pinfo->cinfo, COL_PROTOCOL)) { + static const char *version_names[] = { "1", "2", "2.5" }; + col_add_fstr(pinfo->cinfo, COL_PROTOCOL, + "MPEG-%s", version_names[MPA_VERSION(&mpa)]); + } + if (check_col(pinfo->cinfo, COL_INFO)) + col_add_fstr(pinfo->cinfo, COL_INFO, + "Audio Layer %d", MPA_LAYER(&mpa) + 1); + if (MPA_BITRATE_VALID(&mpa) && MPA_FREQUENCY_VALID(&mpa)) { + data_size = MPA_DATA_BYTES(&mpa) - sizeof mpa; + if (check_col(pinfo->cinfo, COL_DEF_SRC)) { + SET_ADDRESS(&pinfo->src, AT_NONE, 0, NULL); + col_add_fstr(pinfo->cinfo, COL_DEF_SRC, + "%d kb/s", MPA_BITRATE(&mpa) / 1000); + } + if (check_col(pinfo->cinfo, COL_DEF_DST)) { + SET_ADDRESS(&pinfo->dst, AT_NONE, 0, NULL); + col_add_fstr(pinfo->cinfo, COL_DEF_DST, + "%g kHz", MPA_FREQUENCY(&mpa) / (float)1000); + } + } if (tree == NULL) return TRUE; @@ -538,6 +534,8 @@ dissect_id3v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "ID3v1"); + if (check_col(pinfo->cinfo, COL_INFO)) + col_clear(pinfo->cinfo, COL_INFO); if (tree == NULL) return; asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo); @@ -550,6 +548,8 @@ dissect_id3v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "ID3v2"); + if (check_col(pinfo->cinfo, COL_INFO)) + col_clear(pinfo->cinfo, COL_INFO); proto_tree_add_item(tree, hf_id3v2, tvb, 0, -1, FALSE); } @@ -559,11 +559,8 @@ dissect_mpeg_audio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { int magic; - if (check_col(pinfo->cinfo, COL_PROTOCOL)) - col_clear(pinfo->cinfo, COL_PROTOCOL); - if (check_col(pinfo->cinfo, COL_INFO)) - col_clear(pinfo->cinfo, COL_INFO); - + if (!tvb_bytes_exist(tvb, 0, 3)) + return FALSE; /* not enough data for an ID tag or audio frame */ magic = tvb_get_ntoh24(tvb, 0); switch (magic) { case 0x544147: /* TAG */ @@ -577,8 +574,6 @@ dissect_mpeg_audio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } } -static int proto_mpeg_audio = -1; - void proto_register_mpeg_audio(void) { @@ -676,7 +671,7 @@ proto_register_mpeg_audio(void) "mpeg_audio.T_genre", HFILL }}, /*--- End of included file: packet-mpeg-audio-hfarr.c ---*/ -#line 175 "packet-mpeg-audio-template.c" +#line 170 "packet-mpeg-audio-template.c" { &hf_mpeg_audio, { "MPEG Audio", "mpeg.audio", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }}, @@ -703,12 +698,9 @@ proto_register_mpeg_audio(void) &ett_mpeg_audio_ID3v1, /*--- End of included file: packet-mpeg-audio-ettarr.c ---*/ -#line 195 "packet-mpeg-audio-template.c" +#line 190 "packet-mpeg-audio-template.c" }; - if (proto_mpeg_audio != -1) - return; - proto_mpeg_audio = proto_register_protocol( "Moving Picture Experts Group Audio", "MPEG Audio", "mpeg.audio"); proto_register_field_array(proto_mpeg_audio, hf, array_length(hf)); |