Don't pass ep_alloc()'ed strings to col_set_str().

Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3984

svn path=/trunk/; revision=29726
This commit is contained in:
Kovarththanan Rajaratnam 2009-09-06 04:26:50 +00:00
parent a9e644f382
commit 6fe1060cd1
22 changed files with 44 additions and 23 deletions

View File

@ -352,7 +352,7 @@ dissect_camel_camelPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn
if (check_col(actx->pinfo->cinfo, COL_INFO)){
/* Populate the info column with PDU type*/
col_set_str(actx->pinfo->cinfo, COL_INFO, val_to_str(camel_pdu_type, camel_Component_vals, "Unknown Camel (%u)"));
col_add_fstr(actx->pinfo->cinfo, COL_INFO, val_to_str(camel_pdu_type, camel_Component_vals, "Unknown Camel (%u)"));
col_append_str(actx->pinfo->cinfo, COL_INFO, " ");
}

View File

@ -1750,7 +1750,7 @@ dissect_gsm_map_GSMMAPPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
gsm_map_pdu_size = tvb_get_guint8(tvb, offset+1)+2;
if (check_col(actx->pinfo->cinfo, COL_INFO)){
col_set_str(actx->pinfo->cinfo, COL_INFO, val_to_str(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP PDU (%u)"));
col_add_fstr(actx->pinfo->cinfo, COL_INFO, val_to_str(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP PDU (%u)"));
col_append_fstr(actx->pinfo->cinfo, COL_INFO, " ");
}
offset = dissect_gsm_old_Component(FALSE, tvb, 0, actx, tree, hf_gsm_map_old_Component_PDU);

View File

@ -158,7 +158,7 @@ static int dissect_cmp_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *pa
}
if (check_col (pinfo->cinfo, COL_INFO)) {
col_set_str (pinfo->cinfo, COL_INFO, val_to_str (pdu_type, cmp_pdu_types, "0x%x"));
col_add_fstr (pinfo->cinfo, COL_INFO, val_to_str (pdu_type, cmp_pdu_types, "0x%x"));
}
switch(pdu_type){

View File

@ -100,7 +100,7 @@ dissect_smrse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMRSE");
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(tag, tag_vals,"Unknown Tag:0x%02x"));
col_add_fstr(pinfo->cinfo, COL_INFO, val_to_str(tag, tag_vals,"Unknown Tag:0x%02x"));
proto_tree_add_item(tree, hf_smrse_reserved, tvb, 0, 1, FALSE);
proto_tree_add_item(tree, hf_smrse_length, tvb, 1, 2, FALSE);

View File

@ -7102,7 +7102,7 @@ dissect_camel_camelPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn
if (check_col(actx->pinfo->cinfo, COL_INFO)){
/* Populate the info column with PDU type*/
col_set_str(actx->pinfo->cinfo, COL_INFO, val_to_str(camel_pdu_type, camel_Component_vals, "Unknown Camel (%u)"));
col_add_fstr(actx->pinfo->cinfo, COL_INFO, val_to_str(camel_pdu_type, camel_Component_vals, "Unknown Camel (%u)"));
col_append_str(actx->pinfo->cinfo, COL_INFO, " ");
}

View File

@ -794,7 +794,7 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, gint offset,
}
offset++;
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(opcode, rlc_op_vals, "Unknown"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(opcode, rlc_op_vals, "Unknown"));
/* Assume UE side, so REQ is UL, IND is DL */
switch (opcode) {

View File

@ -1544,7 +1544,7 @@ static int dissect_cmp_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *pa
}
if (check_col (pinfo->cinfo, COL_INFO)) {
col_set_str (pinfo->cinfo, COL_INFO, val_to_str (pdu_type, cmp_pdu_types, "0x%x"));
col_add_fstr (pinfo->cinfo, COL_INFO, val_to_str (pdu_type, cmp_pdu_types, "0x%x"));
}
switch(pdu_type){

View File

@ -784,7 +784,7 @@ dissect_dlm3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str(h_cmd,
val_to_str_const(h_cmd,
dlm3_cmd,
"packet-dlm3.c internal bug"));

View File

@ -17569,7 +17569,7 @@ dissect_gsm_map_GSMMAPPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
gsm_map_pdu_size = tvb_get_guint8(tvb, offset+1)+2;
if (check_col(actx->pinfo->cinfo, COL_INFO)){
col_set_str(actx->pinfo->cinfo, COL_INFO, val_to_str(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP PDU (%u)"));
col_add_fstr(actx->pinfo->cinfo, COL_INFO, val_to_str(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP PDU (%u)"));
col_append_fstr(actx->pinfo->cinfo, COL_INFO, " ");
}
offset = dissect_gsm_old_Component(FALSE, tvb, 0, actx, tree, hf_gsm_map_old_Component_PDU);

View File

@ -435,7 +435,7 @@ dissect_hip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
control_h = tvb_get_ntohs(tvb, newoffset);
newoffset += 2;
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(hiph_packet_type, pinfo_vals, "Unknown"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(hiph_packet_type, pinfo_vals, "Unknown"));
/* populate a tree in the second pane with the status of the link layer (i.e. none) */
if(tree) {

View File

@ -366,7 +366,7 @@ dissect_ieee802154_fcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee
/* Display the frame type. */
if (tree) proto_item_append_text(tree, " %s", val_to_str(packet->frame_type, ieee802154_frame_types, "Reserved"));
if (check_col(pinfo->cinfo, COL_INFO)) col_set_str(pinfo->cinfo, COL_INFO, val_to_str(packet->frame_type, ieee802154_frame_types, "Reserved"));
if (check_col(pinfo->cinfo, COL_INFO)) col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet->frame_type, ieee802154_frame_types, "Reserved"));
/* Add the FCF to the protocol tree. */
if (tree) {
@ -1117,7 +1117,7 @@ dissect_ieee802154_cmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ieee
/* Get and display the command frame identifier. */
cmd_id = tvb_get_guint8(tvb, offset);
if(check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cmd_id, ieee802154_cmd_names, "Unknown Command"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(cmd_id, ieee802154_cmd_names, "Unknown Command"));
}
if (tree) {
/* Create a subtree for this command frame. */

View File

@ -269,7 +269,7 @@ dissect_mtp2_lssu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_tree)
proto_tree_add_item(mtp2_tree, hf_mtp2_sf_extra, su_tvb, sf_extra_offset, SF_EXTRA_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(sf, status_field_acro_vals, "Unknown"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(sf, status_field_acro_vals, "Unknown"));
}
static void

View File

@ -105,7 +105,7 @@ static void dissect_nat_pmp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
op_ti = proto_tree_add_item (nat_pmp_tree, hf_opcode, tvb, offset, 1, FALSE);
offset++;
col_set_str (pinfo->cinfo, COL_INFO, val_to_str (opcode, opcode_vals, "Unknown opcode: %d"));
col_add_fstr (pinfo->cinfo, COL_INFO, val_to_str (opcode, opcode_vals, "Unknown opcode: %d"));
switch (opcode) {

View File

@ -2258,13 +2258,13 @@ dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
ptp2_managementErrorId_vals, "Unknown Error Id %u"));
break;
default:
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
col_add_fstr(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
break;
}
}
else
{
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
col_add_fstr(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
}
}

View File

@ -277,7 +277,7 @@ dissect_rpl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str(rpl_type, rpl_type_vals, "Unknown Type"));
val_to_str_const(rpl_type, rpl_type_vals, "Unknown Type"));
}
if (tree) {
ti = proto_tree_add_item(tree, proto_rpl, tvb, 0,

View File

@ -528,7 +528,7 @@ dissect_smrse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMRSE");
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(tag, tag_vals,"Unknown Tag:0x%02x"));
col_add_fstr(pinfo->cinfo, COL_INFO, val_to_str(tag, tag_vals,"Unknown Tag:0x%02x"));
proto_tree_add_item(tree, hf_smrse_reserved, tvb, 0, 1, FALSE);
proto_tree_add_item(tree, hf_smrse_length, tvb, 1, 2, FALSE);

View File

@ -213,7 +213,7 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if(check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO,
val_to_str(cmd, cmd_vs,
val_to_str_const(cmd, cmd_vs,
"Unrecognized packet type"));
}

View File

@ -965,7 +965,7 @@ static void dissect_zbee_aps_cmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
/* Add the command name to the info column. */
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cmd_id, zbee_aps_cmd_names, "Unknown Command"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(cmd_id, zbee_aps_cmd_names, "Unknown Command"));
}
/* Handle the contents of the command frame. */

View File

@ -414,7 +414,7 @@ dissect_zbee_nwk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_item_append_text(proto_root, " %s", val_to_str(packet.type, zbee_nwk_frame_types, "Unknown Type"));
}
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(packet.type, zbee_nwk_frame_types, "Reserved Frame Type"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(packet.type, zbee_nwk_frame_types, "Reserved Frame Type"));
}
/* Get the destination address. */
@ -641,7 +641,7 @@ static void dissect_zbee_nwk_cmd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *
/* Add the command name to the info column. */
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cmd_id, zbee_nwk_cmd_names, "Unknown Command"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(cmd_id, zbee_nwk_cmd_names, "Unknown Command"));
}
/* Handle the command. */

View File

@ -1121,7 +1121,7 @@ dissect_zbee_zdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_item_append_text(zdp_tree, ", %s", val_to_str(cluster, zbee_zdp_cluster_names, "Unknown Cluster"));
}
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cluster, zbee_zdp_cluster_names, "Unknown Cluster"));
col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(cluster, zbee_zdp_cluster_names, "Unknown Cluster"));
}
/* Create a new tvb for the zdp message. */

View File

@ -49,6 +49,22 @@ val_to_str(guint32 val, const value_string *vs, const char *fmt) {
return ep_strdup_printf(fmt, val);
}
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr on a match.
Returns 'unknown_str', on failure. */
const gchar*
val_to_str_const(guint32 val, const value_string *vs, const char *unknown_str) {
const gchar *ret;
g_assert(unknown_str != NULL);
ret = match_strval(val, vs);
if (ret != NULL)
return ret;
return unknown_str;
}
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr, and sets "*idx" to the index in
that table, on a match, and returns NULL, and sets "*idx" to -1,

View File

@ -65,6 +65,11 @@ extern const gchar* match_strval(guint32 val, const value_string *vs);
Formats val with fmt, and returns the resulting string, on failure. */
extern const gchar* val_to_str(guint32 val, const value_string *vs, const char *fmt);
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr on a match.
Returns 'unknown_str', on failure. */
extern const gchar* val_to_str_const(guint32 val, const value_string *vs, const char *unknown_str);
/* Tries to match val against each element in the value_string array vs.
Returns the associated string ptr, and sets "*idx" to the index in
that table, on a match, and returns NULL, and sets "*idx" to -1,