PROFINET: Add strings with proto_tree_add_item

Add strings with proto_tree_add_item instead of tvb_memcpy,
appending a null, and a proto_tree_add_string so that the
strings are validated for encoding, trailing nulls, etc.

Fix #18847
This commit is contained in:
John Thacker 2023-02-07 07:20:27 -05:00
parent c62aa67d2c
commit e8db896c62
1 changed files with 6 additions and 30 deletions

View File

@ -746,12 +746,6 @@ dissect_PDRsiInstances_block(tvbuff_t *tvb, int offset,
const int HWrevision_size = 5; const int HWrevision_size = 5;
const int SWrevisionprefix_size = 1; const int SWrevisionprefix_size = 1;
const int SWrevision_size = 9; const int SWrevision_size = 9;
char *deviceType;
char *orderID;
char *IMserialnumber;
char *HWrevision;
char *SWrevisionprefix;
char *SWrevision;
if (u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) { if (u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) {
expert_add_info_format(pinfo, item, &ei_pn_rsi_error, expert_add_info_format(pinfo, item, &ei_pn_rsi_error,
@ -792,53 +786,35 @@ dissect_PDRsiInstances_block(tvbuff_t *tvb, int offset,
/* SystemIdentification */ /* SystemIdentification */
/* DeviceType */ /* DeviceType */
deviceType = (char *)wmem_alloc(pinfo->pool, deviceType_size + 1); proto_tree_add_item(tree, hf_pn_rsi_device_type, tvb, offset, deviceType_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)deviceType, offset, 25);
deviceType[deviceType_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_device_type, tvb, offset, deviceType_size, deviceType);
offset += deviceType_size + 1; offset += deviceType_size + 1;
/* Blank */ /* Blank */
/* OrderID */ /* OrderID */
orderID = (char *)wmem_alloc(pinfo->pool, orderID_size + 1); proto_tree_add_item(tree, hf_pn_rsi_order_id, tvb, offset, orderID_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)orderID, offset, 20);
orderID[orderID_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_order_id, tvb, offset, orderID_size, orderID);
offset += orderID_size + 1; offset += orderID_size + 1;
/* Blank */ /* Blank */
/* IM_Serial_Number */ /* IM_Serial_Number */
IMserialnumber = (char *)wmem_alloc(pinfo->pool, IMserialnumber_size + 1); proto_tree_add_item(tree, hf_pn_rsi_im_serial_number, tvb, offset, IMserialnumber_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)IMserialnumber, offset, 16);
IMserialnumber[IMserialnumber_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_im_serial_number, tvb, offset, IMserialnumber_size, IMserialnumber);
offset += IMserialnumber_size + 1; offset += IMserialnumber_size + 1;
/* Blank */ /* Blank */
/* HWRevision */ /* HWRevision */
HWrevision = (char *)wmem_alloc(pinfo->pool, HWrevision_size + 1); proto_tree_add_item(tree, hf_pn_rsi_hw_revision, tvb, offset, HWrevision_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)HWrevision, offset, 5);
HWrevision[HWrevision_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_hw_revision, tvb, offset, HWrevision_size, HWrevision);
offset += HWrevision_size + 1; offset += HWrevision_size + 1;
/* Blank */ /* Blank */
/* SWRevisionPrefix */ /* SWRevisionPrefix */
SWrevisionprefix = (char *)wmem_alloc(pinfo->pool, SWrevisionprefix_size + 1); proto_tree_add_item(tree, hf_pn_rsi_sw_revision_prefix, tvb, offset, SWrevisionprefix_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)SWrevisionprefix, offset, 1);
SWrevisionprefix[SWrevisionprefix_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_sw_revision_prefix, tvb, offset, SWrevisionprefix_size, SWrevisionprefix);
offset += SWrevisionprefix_size; offset += SWrevisionprefix_size;
/* SWRevision */ /* SWRevision */
SWrevision = (char *)wmem_alloc(pinfo->pool, SWrevision_size + 1); proto_tree_add_item(tree, hf_pn_rsi_sw_revision, tvb, offset, SWrevision_size, ENC_UTF_8);
tvb_memcpy(tvb, (guint8 *)SWrevision, offset, 9);
SWrevision[SWrevision_size] = '\0';
proto_tree_add_string(tree, hf_pn_rsi_sw_revision, tvb, offset, SWrevision_size, SWrevision);
offset += SWrevision_size; offset += SWrevision_size;
return offset; return offset;
} }