S7Comm: Fix invalid UTF-8 value string chars

Fixes #18533.
This commit is contained in:
João Valverde 2022-10-25 03:04:45 +01:00
parent 56ee77d525
commit 40ec1adfb0
5 changed files with 27 additions and 5 deletions

View File

@ -3308,7 +3308,7 @@ s7comm_decode_pi_service(tvbuff_t *tvb,
col_append_str(pinfo->cinfo, COL_INFO, ", ");
}
itemadd = proto_tree_add_item(file_tree, hf_s7comm_data_blockcontrol_dest_filesys, tvb, paramoffset, 1, ENC_ASCII);
proto_item_append_text(itemadd, " (%s)", val_to_str(tvb_get_guint8(tvb, paramoffset), blocktype_attribute2_names, "Unknown filesys: %c"));
proto_item_append_text(itemadd, " (%s)", char_val_to_str(tvb_get_guint8(tvb, paramoffset), blocktype_attribute2_names, "Unknown filesys"));
paramoffset += 1;
}
col_append_str(pinfo->cinfo, COL_INFO, ")");
@ -3667,7 +3667,7 @@ s7comm_decode_plc_controls_filename(tvbuff_t *tvb,
col_append_str(pinfo->cinfo, COL_INFO, "NaN]");
}
itemadd = proto_tree_add_item(file_tree, hf_s7comm_data_blockcontrol_dest_filesys, tvb, offset, 1, ENC_ASCII);
proto_item_append_text(itemadd, " (%s)", val_to_str(tvb_get_guint8(tvb, offset), blocktype_attribute2_names, "Unknown filesys: %c"));
proto_item_append_text(itemadd, " (%s)", char_val_to_str(tvb_get_guint8(tvb, offset), blocktype_attribute2_names, "Unknown filesys"));
offset += 1;
}
}
@ -6221,7 +6221,7 @@ s7comm_decode_ud_block_subfunc(tvbuff_t *tvb,
}
offset += 5;
itemadd = proto_tree_add_item(data_tree, hf_s7comm_ud_blockinfo_filesys, tvb, offset, 1, ENC_ASCII);
proto_item_append_text(itemadd, " (%s)", val_to_str(tvb_get_guint8(tvb, offset), blocktype_attribute2_names, "Unknown filesys: %c"));
proto_item_append_text(itemadd, " (%s)", char_val_to_str(tvb_get_guint8(tvb, offset), blocktype_attribute2_names, "Unknown filesys"));
offset += 1;
}
know_data = TRUE;

View File

@ -237,7 +237,6 @@ static void fill_label_number64(field_info *fi, gchar *label_str, gboolean is_si
static size_t fill_display_label_float(field_info *fi, gchar *label_str);
static void fill_label_float(field_info *fi, gchar *label_str);
static const char *hfinfo_char_value_format_display(int display, char buf[7], guint32 value);
static const char *hfinfo_number_value_format_display(const header_field_info *hfinfo, int display, char buf[32], guint32 value);
static const char *hfinfo_number_value_format_display64(const header_field_info *hfinfo, int display, char buf[48], guint64 value);
static const char *hfinfo_char_vals_format(const header_field_info *hfinfo, char buf[32], guint32 value);
@ -10103,7 +10102,7 @@ hfinfo_hex_digits(const header_field_info *hfinfo)
return (bitwidth + 3) / 4;
}
static const char *
const char *
hfinfo_char_value_format_display(int display, char buf[7], guint32 value)
{
char *ptr = &buf[6];

View File

@ -3357,6 +3357,9 @@ proto_custom_set(proto_tree* tree, GSList *field_id,
/** @} */
const char *
hfinfo_char_value_format_display(int display, char buf[7], guint32 value);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -106,6 +106,22 @@ try_val_to_str(const guint32 val, const value_string *vs)
return try_val_to_str_idx(val, vs, &ignore_me);
}
const gchar *
char_val_to_str(char val, const value_string *vs, const char *msg)
{
const gchar *ret;
char buf[7];
DISSECTOR_ASSERT(msg != NULL);
ret = try_val_to_str(val, vs);
if (ret != NULL)
return ret;
return wmem_strdup_printf(wmem_packet_scope(), "%s: %s",
msg, hfinfo_char_value_format_display(BASE_HEX, buf, val));
}
/* 64-BIT VALUE STRING */
const gchar *

View File

@ -124,6 +124,10 @@ WS_DLL_PUBLIC
const gchar *
try_val_to_str_idx(const guint32 val, const value_string *vs, gint *idx);
WS_DLL_PUBLIC
const gchar *
char_val_to_str(char val, const value_string *vs, const char *msg);
/* 64-BIT VALUE TO STRING MATCHING */
typedef struct _val64_string {